Bug in talloc_asprintf_append()

Jeremy Allison jra at samba.org
Wed Sep 12 21:15:40 GMT 2007


On Wed, Sep 12, 2007 at 02:12:56PM -0700, Jeremy Allison wrote:
> Tridge,
> 
> 	The talloc_asprintf_append() function doesn't take
> into account a truncated string.
> 
> Imagine the following :
> 
> 	/* talloc a 10 byte string. */
> 	char *s = talloc_strdup(NULL, "0123456789");
> 
> 	s[5] = '\0';
> 
> 	s = talloc_asprintf_append(s,
> 				"%s",
> 				"56789");
> 
> The result of s will be :
> 
> 	+---------------------------------+
> 	|0|1|2|3|4|\0|6|7|8|9|5|6|7|8|9|\0|
> 	+---------------------------------+
> 
> instead of :
> 
> 	+--------------------------------+
> 	|0|1|2|3|4|5|6|7|8|9|5|6|7|8|9|\0|
> 	+--------------------------------+


Doh, I meant - instead of :

 	+----------------------+
 	|0|1|2|3|4|5|6|7|8|9|\0|
 	+----------------------+

- I hope you get what I mean :-).


More information about the samba-technical mailing list