svn commit: r334275 - head/lib/libc/string

Mariusz Zaborski oshogbo at FreeBSD.org
Mon May 28 13:22:01 UTC 2018


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-head/attachments/20180528/6609d9ce/attachment.sig>


More information about the svn-src-head mailing list