[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKgNAkjZ31JAs0XFutnAozCAcHHAq6pcCAKeDNHccKQ+6uTP6g@mail.gmail.com>
Date: Thu, 19 Apr 2012 22:33:03 +1200
From: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>
To: Alan Cox <alan@...rguk.ukuu.org.uk>
Cc: David Miller <davem@...emloft.net>, carlos@...temhalted.org,
netdev@...r.kernel.org, penguin-kernel@...ove.sakura.ne.jp,
linux-api@...r.kernel.org, yoshfuji@...ux-ipv6.org,
jengelh@...ozas.de, w@....eu
Subject: Re: [patch] Fix handling of overlength pathname in AF_UNIX sun_path
On Thu, Apr 19, 2012 at 10:19 PM, Alan Cox <alan@...rguk.ukuu.org.uk> wrote:
>> 3. Considering these two sets:
>>
>> (a) [applications that rely on the assumption that there
>> is a null terminator inside sizeof(sun_path) bytes]
>> (b) [applications that would break if the kernel behavior changed]
>>
>> I suspect that set (a) is rather larger than set (b)--or, more
>> likely still, applications ensure they go for the lowest common
>> denominator limit of 92 (HP-UX) or 104 (historical BSD limit)
>> bytes, and so avoid this issue completely.
>
> Or another way of putting it
>
> 3(a) Sloppy coding that may have lots of other bugs
>
> 3(b) Interfaces and code we promised not to break.
Yes, it's another way of putting it. (Though regarding 3(b), part of
the problem is that there never was a clearly specified contract.)
Anyway, I've dug deeper, looking at hat happens on other platforms.
It's a mess: the BSDs don't even guarantee that sun_path is
null_terminated. So, here's how one has to portably deal with the
variations:
addrlen = sizeof(struct sockaddr_un);
cfd = accept(lfd, &addr, &addlen);
printf("%.*s", addrlen - offsetof(struct sockaddr_un, sun_path), addr.sun_path);
That's pretty hideous!
Thanks,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Author of "The Linux Programming Interface"; http://man7.org/tlpi/
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists