[systemd-devel] [PATCH] resolved: re-add support for getting local domain from DHCP

Lennart Poettering lennart at poettering.net
Mon Aug 4 08:21:46 PDT 2014


On Wed, 30.07.14 00:37, Zbigniew Jędrzejewski-Szmek (zbyszek at in.waw.pl) wrote:

> > +_public_ int sd_network_get_domainname(int ifindex, char **domainname) {
> > +        _cleanup_free_ char *s = NULL, *p = NULL;
> > +        int r;
> > +
> > +        assert_return(ifindex > 0, -EINVAL);
> > +        assert_return(domainname, -EINVAL);
> > +
> > +        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
> > +                return -ENOMEM;
> Not terribly important, but please spell that as:
> 
>            char p[sizeof("/run/systemd/netif/links/") + DECIMAL_STRING_MAX(int)];
> 	   snprintf(p, sizeof(p), "/run/systemd/netif/links/%d",
> 	   ifindex);

Actually, I'd even use normal sprintf() here, not snprintf(), after all,
we carefully sized the string anyway, hence no need to enforce the size
limit here. In particular since snprintf() doesn't add a trailing NULL
if it truncates the string, which makes the whole excercise kinda
pointless... an snprintf() without something like char_array_0() invoked
right after it always raises my eyebrows. Using sprintf() here makes is
clear to me that the buffer was carefully sized before, so I think would
be preferrable...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list