From owner-freebsd-current Mon Oct 21 14:01:34 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id OAA11544 for current-outgoing; Mon, 21 Oct 1996 14:01:34 -0700 (PDT) Received: from cabri.obs-besancon.fr (cabri.obs-besancon.fr [193.52.184.3]) by freefall.freebsd.org (8.7.5/8.7.3) with SMTP id OAA11536 for ; Mon, 21 Oct 1996 14:01:28 -0700 (PDT) Received: by cabri.obs-besancon.fr (5.57/Ultrix3.0-C) id AA15621; Mon, 21 Oct 96 23:07:27 +0100 Date: Mon, 21 Oct 96 23:07:27 +0100 Message-Id: <9610212207.AA15621@cabri.obs-besancon.fr> From: Jean-Marc Zucconi To: wollman@lcs.mit.edu Cc: freebsd-current@freebsd.org In-Reply-To: <9610211430.AA13042@halloran-eldar.lcs.mit.edu> (message from Garrett Wollman on Mon, 21 Oct 1996 10:30:07 -0400) Subject: Re: socket (AF_UNIX) bug X-Mailer: Emacs Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk >>>>> Garrett Wollman writes: > < 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 =============================================================================