Date: Mon, 21 Oct 96 23:07:27 +0100 From: Jean-Marc Zucconi <jmz@cabri.obs-besancon.fr> To: wollman@lcs.mit.edu Cc: freebsd-current@freebsd.org Subject: Re: socket (AF_UNIX) bug Message-ID: <9610212207.AA15621@cabri.obs-besancon.fr> In-Reply-To: <9610211430.AA13042@halloran-eldar.lcs.mit.edu> (message from Garrett Wollman on Mon, 21 Oct 1996 10:30:07 -0400)
next in thread | previous in thread | raw e-mail | index | archive | help
>>>>> Garrett Wollman writes: > <<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 */ OK, I thought it was a bug because 1 - I do not wrote it :-) - it comes from a package I ported to freebsd. 2 - I looked in the Stevens book and he gives the same expression for addrlen (see p294) 3 - this works on the machines on which I tried (ultrix, osf, sunos) I think that bind() should be modified so that it does not ignore the extra byte, if the rest of the string is padded with nuls. This for compatibility reasons. Jean-Marc _____________________________________________________________________________ Jean-Marc Zucconi Observatoire de Besancon F 25010 Besancon cedex PGP Key: finger jmz@cabri.obs-besancon.fr =============================================================================
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9610212207.AA15621>