From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Tetsuo Handa
<penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp@public.gmane.org>
Cc: linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Michael Kerrisk
<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: Re: Patch for man unix(7)
Date: Mon, 16 Apr 2012 09:42:48 +1200 [thread overview]
Message-ID: <CAKgNAkgNRbdcWwo0nhsbCxtnagEucxm6d76ugGAAUAd+ukBLCQ@mail.gmail.com> (raw)
In-Reply-To: <201011232159.DFE78143.tSHMFQOLFVFJOO-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
Hello Tetsuao Handa
[Thanks for the text program that you sent more recently]
On Wed, Nov 24, 2010 at 1:59 AM, Tetsuo Handa
<penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp@public.gmane.org> wrote:
> From f388eedbdc0b099bb9f36ab007f9370432abb300 Mon Sep 17 00:00:00 2001
> From: Tetsuo Handa <penguin-kernel-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
> Date: Tue, 23 Nov 2010 21:34:25 +0900
> Subject: [PATCH] unix.7: Fix description of "pathname" sockets
>
> Since unix_mkname() in net/unix/af_unix.c does
>
> ((char *)sunaddr)[len] = 0;
>
> rather than
>
> ((char *)sunaddr)[len - 1] = 0;
>
> , sunaddr->sun_path may not be terminated with a null byte if
> len == sizeof(*sunaddr).
>
> Therefore, the caller of getsockname(), getpeername(), accept() must not assume
> that sunaddr->sun_path contains a null-terminated pathname even if the returned
> addrlen is greater than sizeof(sa_family_t) and sun_path[0] != '\0'.
Thanks. I see what you mean. However, I'm wondering, is the kernel
behavior simply a bug that should be fixed, so that a null terminator
is always placed in sun_path?
I realize that's an ABI change, but:
a) I suspect most sane applications would never create a sun_path that
didn't contain a null terminator within sizeof(sun_path) bytes.
b) Considering these two sets:
1. [applications that would break if the assumption that there
is no null terminator inside sizeof(sun_path) bytes doesn't
hold true]
2. [applications that would break if the kernel behavior changed]
I suspect that set 1 is much larger than set 2.
Your thoughts?
Thanks,
Michael
> Signed-off-by: Tetsuo Handa <penguin-kernel-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
> ---
> man7/unix.7 | 19 ++++++++++++++++---
> 1 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/man7/unix.7 b/man7/unix.7
> index b53328b..7b0b47c 100644
> --- a/man7/unix.7
> +++ b/man7/unix.7
> @@ -80,10 +80,23 @@ When the address of the socket is returned by
> and
> .BR accept (2),
> its length is
> -.IR "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1" ,
> +.IR "offsetof(struct sockaddr_un, sun_path) + strlen(sun_path) + 1".
> +Note that this length can be one byte larger than
> +.IR "sizeof(struct sockaddr_un)"
> +because
> +.BR bind (2)
> +accepts
> +.IR sun_path
> +which is not terminated with a null byte ('\\0').
> +Therefore, you must not use string manipulation functions (e.g. strlen(),
> +printf("%s")) against
> +.IR sun_path
> +because
> +.BR getsockname (2),
> +.BR getpeername (2),
> and
> -.I sun_path
> -contains the null-terminated pathname.
> +.BR accept (2)
> +may not have stored a null-terminated string.
> .IP *
> .IR unnamed :
> A stream socket that has not been bound to a pathname using
> --
> 1.6.1
--
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 linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2012-04-15 21:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-10 5:48 Documenting UNIX domain autobind Michael Kerrisk
2010-10-17 5:28 ` Tetsuo Handa
2010-10-26 12:15 ` Question on UNIX domain socket Tetsuo Handa
[not found] ` <201010262115.FEH09326.OMFJHSVOFLQFOt-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2010-11-23 12:59 ` Patch for man unix(7) Tetsuo Handa
[not found] ` <201011232159.DFE78143.tSHMFQOLFVFJOO-JPay3/Yim36HaxMnTkn67Xf5DAMn2ifp@public.gmane.org>
2012-04-15 21:42 ` Michael Kerrisk (man-pages) [this message]
[not found] ` <CAKgNAkgNRbdcWwo0nhsbCxtnagEucxm6d76ugGAAUAd+ukBLCQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-04-15 22:40 ` Michael Kerrisk (man-pages)
2012-04-16 11:08 ` Tetsuo Handa
2012-04-15 21:07 ` Documenting UNIX domain autobind Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKgNAkgNRbdcWwo0nhsbCxtnagEucxm6d76ugGAAUAd+ukBLCQ@mail.gmail.com \
--to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=penguin-kernel-1yMVhJb1mP/7nzcFbJAaVXf5DAMn2ifp@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).