Bug in talloc_asprintf_append()

Jeremy Allison jra at samba.org
Fri Sep 14 16:43:59 GMT 2007


On Fri, Sep 14, 2007 at 04:05:52PM +0200, Stefan (metze) Metzmacher wrote:
> > I changed talloc_asprintf_append() to use strlen in the
> > length calculation, and now all my smbtorture tests pass
> > as talloc_asprintf_append() is doing what it's name would
> > suggest. If this gets reverted I'll have to remove all
> > use of talloc_asprintf_append() from the fileserving code,
> > as in it's original state it doesn't work with talloced
> > strings that have been truncated deliberately.
> 
> Hi Jeremy,
> 
> Where are this usages? the two in smbd/trans2.c?
> 
> I just noticed a bug:
> 
>                 rel_name = talloc_asprintf_append(ctx,
>                                 "%s",
>                                 link_target);
> 
> 'ctx' is totaly wrong there:-)

Thanks ! Fixing now...

I knew there'd be some bugs in this large a change,
so thanks for doing the reviews.

> and this:
>                 rel_name = talloc_strdup(ctx,newname);
>                 if (!rel_name) {
>                         return NT_STATUS_NO_MEMORY;
>                 }
>                 last_dirp = strrchr_m(rel_name, '/');
>                 if (last_dirp) {
>                         last_dirp[1] = '\0';
>                 } else {
>                         rel_name = talloc_strdup(ctx,"./");
>                         if (!rel_name) {
>                                 return NT_STATUS_NO_MEMORY;
>                         }
>                 }
> could use strrchr_m(newname)
> and then you can do:
> 
> if (last_dirp) {
> 
> 	rel_name = talloc_strndup(ctx,
> 				PTR_DIFF(last_dirp,newname),
> 				newname);
> }
> 
> (and then the optimized '_append_end' version can be used:-)

I'll take a look at this.

Thanks,

Jeremy.


More information about the samba-technical mailing list