Bug in talloc_asprintf_append()

Stefan (metze) Metzmacher metze at samba.org
Fri Sep 14 14:05:52 GMT 2007


> 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:-)

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:-)

metze
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : http://lists.samba.org/archive/samba-technical/attachments/20070914/1e03025b/signature.bin


More information about the samba-technical mailing list