Skip site navigation (1)Skip section navigation (2)
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>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
Hello Marcelo,

Thanks for working on that :)

>  
>  tofree = string = strdup("abc,def,ghi");
> -assert(string != NULL);
> +if (string != NULL)
> +	while ((token = strsep(&string, ",")) != 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.

>  
> -while ((token = strsep(&string, ",")) != 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 reason
would stop at any other point the string will be pointing to the middle of
'tofree' variable which you already freed.

Thanks,
-- 
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

[-- Attachment #2 --]
-----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-----
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180528132106.GA55425>