NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: lib/60054: libedit: adding user defined functions with narrow name/desription leaks memory
The following reply was made to PR lib/60054; it has been noted by GNATS.
From: Kristofer Peterson <kris%tranception.com@localhost>
To: "gnats-bugs" <gnats-bugs%netbsd.org@localhost>
Cc: "lib-bug-people" <lib-bug-people%netbsd.org@localhost>,
"gnats-admin" <gnats-admin%netbsd.org@localhost>,
"netbsd-bugs" <netbsd-bugs%netbsd.org@localhost>
Subject: Re: lib/60054: libedit: adding user defined functions with narrow
name/desription leaks memory
Date: Wed, 04 Mar 2026 04:15:43 +0000
------=_Part_1051427_1479726595.1772597743656
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I originally looked at wcsdup()'ing then freeing each name/description in m=
ap_end.
However the builtin functions all have static strings so can't be freed.
So then I looked at just skipping the first=C2=A0EL_NUM_FCNS entries and fr=
eeing the rest.
Then I saw with el_wset(EL_ADDFN) there was no wcsdup() so I gathered the i=
nterface was supposed to use the passed in strings, as a library user could=
also just have static wstrings for their commands so no point in copying t=
hose. I looked at the man page but it wasn't clear whether EL_ADDFN was sup=
posed to copy the strings or whether the caller had to guarantee the storag=
e lifetime until el_end().
So then I settled on the list of buffers which are only used when narrow na=
me/descriptions strings are passed.
But always copying strings whether narrow or wide would also work (perhaps =
skipping the first EL_NUM_FCNS builtin functions).
Freeing a const char* or const wchar_t* doesn't work though with the compil=
er warnings, you need an ugly double cast (i.e. free((void*)(intptr_t)ptr))=
.
-K
From: Christos Zoulas via gnats <gnats-admin%NetBSD.org@localhost>
To: <lib-bug-people%netbsd.org@localhost>, <gnats-admin%netbsd.org@localhost>, <netbsd-bugs@net=
bsd.org>, <kris%tranception.com@localhost>
Date: Tue, 03 Mar 2026 22:20:03 +0000
Subject: Re: lib/60054: libedit: adding user defined functions with narrow =
name/desription leaks memory
The following reply was made to PR lib/60054; it has been noted by GNATS.=
=20
=20
From: Christos Zoulas < mailto:christos%zoulas.com@localhost >=20
To: mailto:gnats-bugs%netbsd.org@localhost =20
Cc: mailto:lib-bug-people%netbsd.org@localhost ,=20
mailto:gnats-admin%netbsd.org@localhost ,=20
mailto:netbsd-bugs%netbsd.org@localhost =20
Subject: Re: lib/60054: libedit: adding user defined functions with narrow=
=20
name/desription leaks memory=20
Date: Tue, 3 Mar 2026 17:18:35 -0500=20
=20
--Apple-Mail=3D_0DE034AA-DA2B-477C-B795-AA48136AD9B6=20
Content-Transfer-Encoding: quoted-printable=20
Content-Type: text/plain;=20
=C2=A0=C2=A0=C2=A0=C2=A0charset=3Dus-ascii=20
=20
Isn't it simpler to always add strdup() (even in the wide case), and =3D=
=20
then always free the strings?=20
=20
christos=3D=20
=20
--Apple-Mail=3D_0DE034AA-DA2B-477C-B795-AA48136AD9B6=20
Content-Transfer-Encoding: 7bit=20
Content-Disposition: attachment;=20
=C2=A0=C2=A0=C2=A0=C2=A0filename=3Dsignature.asc=20
Content-Type: application/pgp-signature;=20
=C2=A0=C2=A0=C2=A0=C2=A0name=3Dsignature.asc=20
Content-Description: Message signed with OpenPGP=20
=20
-----BEGIN PGP SIGNATURE-----=20
Comment: GPGTools - http://gpgtools.org =20
=20
iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESqxbLM7OgUCaadeOwAKCRBxESqxbLM7=20
OqbKAKCvEIgWP+mNVTTsAY8mpaMtC/1v2ACfS7ElLoVQ4iPgzxX3N0EY5VHlrdQ=3D=20
=3DCgze=20
-----END PGP SIGNATURE-----=20
=20
--Apple-Mail=3D_0DE034AA-DA2B-477C-B795-AA48136AD9B6--
------=_Part_1051427_1479726595.1772597743656
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>=
<meta content=3D"text/html;charset=3DUTF-8" http-equiv=3D"Content-Type"></h=
ead><body ><div style=3D"font-family: Verdana, Arial, Helvetica, sans-serif=
; font-size: 10pt;"><div>I originally looked at wcsdup()'ing then freeing e=
ach name/description in map_end.<br></div><div>However the builtin function=
s all have static strings so can't be freed.<br></div><div>So then I looked=
at just skipping the first EL_NUM_FCNS entries and freeing the rest.<=
br></div><div><br></div><div>Then I saw with el_wset(EL_ADDFN) there was no=
wcsdup() so I gathered the interface was supposed to use the passed in str=
ings, as a library user could also just have static wstrings for their comm=
ands so no point in copying those. I looked at the man page but it wasn't c=
lear whether EL_ADDFN was supposed to copy the strings or whether the calle=
r had to guarantee the storage lifetime until el_end().<br></div><div><br><=
/div><div>So then I settled on the list of buffers which are only used when=
narrow name/descriptions strings are passed.<br></div><div><br></div><div>=
But always copying strings whether narrow or wide would also work (perhaps =
skipping the first EL_NUM_FCNS builtin functions).<br></div><div>Freeing a =
const char* or const wchar_t* doesn't work though with the compiler warning=
s, you need an ugly double cast (i.e. free((void*)(intptr_t)ptr)).</div><di=
v><br></div><div>-K<br></div><div><br></div><div class=3D"zmail_extra_hr" s=
tyle=3D"border-top: 1px solid rgb(204, 204, 204); height: 0px; margin-top: =
10px; margin-bottom: 10px; line-height: 0px;"><br></div><div class=3D"zmail=
_extra" data-zbluepencil-ignore=3D"true"><div><br></div><div id=3D"Zm-_Id_-=
Sgn1">From: Christos Zoulas via gnats <gnats-admin%NetBSD.org@localhost><br>To:=
<lib-bug-people%netbsd.org@localhost>, <gnats-admin%netbsd.org@localhost>, <net=
bsd-bugs%netbsd.org@localhost>, <kris%tranception.com@localhost><br>Date: Tue, 03 Mar =
2026 22:20:03 +0000<br>Subject: Re: lib/60054: libedit: adding user defined=
functions with narrow name/desription leaks memory<br></div><div><br></div=
><blockquote id=3D"blockquote_zmail" style=3D"margin: 0px;"><div>The follow=
ing reply was made to PR lib/60054; it has been noted by GNATS. <br> <br>Fr=
om: Christos Zoulas <<a target=3D"_blank" href=3D"mailto:christos@zoulas=
.com">christos%zoulas.com@localhost</a>> <br>To: <a target=3D"_blank" href=3D"mail=
to:gnats-bugs%netbsd.org@localhost">gnats-bugs%netbsd.org@localhost</a> <br>Cc: <a target=3D"_b=
lank" href=3D"mailto:lib-bug-people%netbsd.org@localhost">lib-bug-people%netbsd.org@localhost</=
a>, <br> <a target=3D"_blank" href=3D"mailto:gnats-admin%netbsd.org@localhost">gnats-=
admin%netbsd.org@localhost</a>, <br> <a target=3D"_blank" href=3D"mailto:netbsd-bugs@=
netbsd.org">netbsd-bugs%netbsd.org@localhost</a> <br>Subject: Re: lib/60054: libedit:=
adding user defined functions with narrow <br> name/desription leaks memor=
y <br>Date: Tue, 3 Mar 2026 17:18:35 -0500 <br> <br> --Apple-Mail=3D_0DE034=
AA-DA2B-477C-B795-AA48136AD9B6 <br> Content-Transfer-Encoding: quoted-print=
able <br> Content-Type: text/plain; <br> charset=3D=
us-ascii <br> <br> Isn't it simpler to always add strdup() (even in the wid=
e case), and =3D <br> then always free the strings? <br> <br> christos=3D <=
br> <br> --Apple-Mail=3D_0DE034AA-DA2B-477C-B795-AA48136AD9B6 <br> Content-=
Transfer-Encoding: 7bit <br> Content-Disposition: attachment; <br> &n=
bsp; filename=3Dsignature.asc <br> Content-Type: application/pgp=
-signature; <br> name=3Dsignature.asc <br> Content-=
Description: Message signed with OpenPGP <br> <br> -----BEGIN PGP SIGNATURE=
----- <br> Comment: GPGTools - <a target=3D"_blank" href=3D"http://gpgtools=
.org">http://gpgtools.org</a> <br> <br> iF0EARECAB0WIQS+BJlbqPkO0MDBdsRxESq=
xbLM7OgUCaadeOwAKCRBxESqxbLM7 <br> OqbKAKCvEIgWP+mNVTTsAY8mpaMtC/1v2ACfS7El=
LoVQ4iPgzxX3N0EY5VHlrdQ=3D <br> =3DCgze <br> -----END PGP SIGNATURE----- <b=
r> <br> --Apple-Mail=3D_0DE034AA-DA2B-477C-B795-AA48136AD9B6-- <br> <br></d=
iv></blockquote></div><div><br></div></div><br></body></html>
------=_Part_1051427_1479726595.1772597743656--
Home |
Main Index |
Thread Index |
Old Index