Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 1996 10:30:07 -0400
From:      Garrett Wollman <wollman@lcs.mit.edu>
To:        Jean-Marc Zucconi <jmz@cabri.obs-besancon.fr>
Cc:        freebsd-current@freebsd.org
Subject:   socket (AF_UNIX) bug
Message-ID:  <9610211430.AA13042@halloran-eldar.lcs.mit.edu>
In-Reply-To: <9610210218.AA09736@cabri.obs-besancon.fr>
References:  <9610210218.AA09736@cabri.obs-besancon.fr>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Mon, 21 Oct 96 03:18:14 +0100, Jean-Marc Zucconi <jmz@cabri.obs-besancon.fr> said:

> The following code creates a socket whose name is 1 char too
> short. A workaround is to add 1 to addrlen before calling bind, but I
> think that the code should  work as is. 

The code is wrong.

>     strncpy (sockaddr.sun_path, path, sizeof(sockaddr.sun_path));
>     addrlen = sizeof(sockaddr.sun_family) + strlen(path);

sizeof(sockaddr.sun_family) == 1
offsetof(struct sockaddr_un, sun_path) == 2

This would be clearer if the sockaddr were properly initialized; i.e.:

>     strncpy (sockaddr.sun_path, path, sizeof(sockaddr.sun_path));
      sockaddr.sun_len = offsetof(struct sockaddr_un, sun_path) 
	+ min(strlen(path), sizeof(sockaddr.sun_path));
>     addrlen = sizeof(sockaddr.sun_family)
	+ min(strlen(path), sizeof(sockaddr.sun_path));
      /* alternatively, addrlen = sockaddr.sun_len */

-GAWollman

--
Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
wollman@lcs.mit.edu  | O Siem / The fires of freedom 
Opinions not those of| Dance in the burning flame
MIT, LCS, ANA, or NSA|                     - Susan Aglukark and Chad Irschick



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9610211430.AA13042>