[systemd-devel] [PATCH] networkd: use valid bus paths

Lennart Poettering lennart at poettering.net
Tue Feb 10 12:02:01 PST 2015


On Fri, 06.02.15 22:35, Mantas Mikulėnas (grawity at gmail.com) wrote:

> Object path components must start with [A-Za-z_] (AFAIK).
> Also the value of 'p' is undefined if asprintf fails.

Well, asprintf() the way glibc defines it does not clobber the
passed-in pointer on failure. We rely on that all over the code, and I
am pretty sure that's the right thing to do. The man page of
asprintf() is a bit misleading in this case, and the info page doesn't
mention this at all. The glibc sources tell show that they indeed
don't clobber the pointer on failure.

Given that p was initialized to NULL the check Tom had in place
originally is OK hence.

And even if glibc asprintf() would clobber passed in pointers on
failure, the right fix would really be to write a small wrapper that
corrects that, and use that everywhere instead of patching this
individually on each invocation...

> @@ -43,7 +43,8 @@ static char *link_bus_path(Link *link) {
>          assert(link);
>          assert(link->ifindex > 0);
>  
> -        asprintf(&p, "/org/freedesktop/network1/link/%d", link->ifindex);
> +        if (asprintf(&p, "/org/freedesktop/network1/link/_%d", link->ifindex) < 0)
> +                return NULL;
>  
>          return p;
>  }


Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list