Date: Mon, 28 May 2018 15:21:06 +0200 From: Mariusz Zaborski <oshogbo@FreeBSD.org> To: Marcelo Araujo <araujo@FreeBSD.org> Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r334275 - head/lib/libc/string Message-ID: <20180528132106.GA55425@jarvis> In-Reply-To: <201805280501.w4S51hbH046599@repo.freebsd.org> References: <201805280501.w4S51hbH046599@repo.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello Marcelo,
Thanks for working on that :)
> =20
> tofree =3D string =3D strdup("abc,def,ghi");
> -assert(string !=3D NULL);
> +if (string !=3D NULL)
> + while ((token =3D strsep(&string, ",")) !=3D NULL)
> + printf("%s\en", token);
Please notice:
```
If *stringp is initially NULL, strsep() returns NULL.
```
So I even not sure if you need to check strdup() at this point.
> =20
> -while ((token =3D strsep(&string, ",")) !=3D NULL)
> - printf("%s\en", token);
> -
> free(tofree);
> +free(string);
Here you introduced potential double free.
At the end of loop the 'string' will be equals to NULL so there is no point=
to
free it. If somebody would use this code as example and he from any other r=
eason
would stop at any other point the string will be pointing to the middle of
'tofree' variable which you already freed.
Thanks,
--=20
Mariusz Zaborski
oshogbo//vx | http://oshogbo.vexillium.org
FreeBSD commiter | https://freebsd.org
Software developer | http://wheelsystems.com
If it's not broken, let's fix it till it is!!1
--ZPt4rx8FFjLCG7dd
Content-Type: application/pgp-signature; name="signature.asc"
-----BEGIN PGP SIGNATURE-----
iQIzBAEBCAAdFiEEkD1x0xkJXVVY1Gwf38KEGuLGxWQFAlsMAkEACgkQ38KEGuLG
xWSLdQ//cUMf/K0NqR/GMCZd5hkGuguhSLcIkCeF3VtroMlULwxNuhRwKU4oTKRp
76wrKxW9Es6UwQ/aztYKQvGd0MRGdvIvx78oHCMa3yYZP3brCQRjMeMCWH5JdSpT
wET29HJec1tqtAssTD8M0FKZap/pD1nHJKiybd9tzBXe8/il/MgwgVfPTNIGvF/d
i/GYdKX0HZ+job4FoREqm4yarH5DFGBQBWSq1aQ3r5BvFO6I/NXQQXU6MSIlkzlu
IFX52jtX3vVubUw/cbYMgtl+ySa7bdYIb2GBOMfDTlxTA/62tAJJELZDhpW07BZw
zZwZS2zQGewA5m4S7KpL2gHLAvOycbMuASbZEl6a1DpD9f3k6yiPjKwhDNeDujYS
Xzdi3YQhwrarN8ilF7Sh63MF53j3UNrm6A8pzEeRG6SZIw6PsNdUpc3xzzG88Ys2
jyAxZnatWvqHUbBpMbdY+sqU/qwnxHJ14Jwuqe8zC3XZK88scE77IDku/Faff03x
FHp49mTuQoTUD1husvsQhvzhfXW+fSdRG3h2Ic3oQKeh2qARd/orvVtxniW9DKY3
T2zllylsMUcBa8hVUY3cJstjqDTytZJqZTl7sGaERvNKcmWe1Mwi8Yo5nHnYFxEf
uiDE0PTPJEdpq/LDOKE0/TG2ScvMa+zBsZJvBecm32xMontqP1Y=
=SIPo
-----END PGP SIGNATURE-----
--ZPt4rx8FFjLCG7dd--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180528132106.GA55425>
