From owner-freebsd-bugs@FreeBSD.ORG Tue May 3 23:10:07 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6C10716A4CE for ; Tue, 3 May 2005 23:10:07 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 46E4743D7E for ; Tue, 3 May 2005 23:10:07 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j43NA4gI077192 for ; Tue, 3 May 2005 23:10:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j43NA4Us077191; Tue, 3 May 2005 23:10:04 GMT (envelope-from gnats) Date: Tue, 3 May 2005 23:10:04 GMT Message-Id: <200505032310.j43NA4Us077191@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Giorgos Keramidas Subject: Re: kern/80587: accept(2) can return EINVAL for undocumented reason X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Giorgos Keramidas List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 May 2005 23:10:07 -0000 The following reply was made to PR kern/80587; it has been noted by GNATS. From: Giorgos Keramidas To: Arne H Juul Cc: bug-followup@freebsd.org Subject: Re: kern/80587: accept(2) can return EINVAL for undocumented reason Date: Wed, 4 May 2005 02:00:22 +0300 On 2005-05-03 20:35, Arne H Juul wrote: > We had a problem where a daemon wouldn't read commands on its socket; > after some debugging we found that accept() on the socket didn't work > (with errno EINVAL). According to man 2 accept this can only be > caused by "listen(2) has not been called" but after more intensive > debugging we couldn't figure out how that was possible in our program. > > Inspection of the actual kernel source for accept(2) however shows > that it also returns EINVAL when the namelen argument is negative; it > turns out the program had a stupid bug where the namelen was > uninitialized causing accept() to fail unpredicably depending on stack > contents. The following documentation fix would (hopefully) have > saved us some time chasing down codepaths through listen(). True! The relevant bits in CURRENT are in uipc_syscalls.c (which you already know, but I'm posting here for the audit trail): 281 static int 282 accept1(td, uap, compat) ... 290 { ... 307 if (namelen < 0) 308 return (EINVAL); > .It Bq Er EINVAL > .Xr listen 2 > has not been called on the socket descriptor. > +.It Bq Er EINVAL > +The > +.Fa addrlen > +argument is negative. I think that documenting both cases in a single paragraph of accept(2) is ok too: .It Bq Er EINVAL .Xr listen 2 -has not been called on the socket descriptor. +has not been called on the socket descriptor or the +.Fa addrlen +argument is negative. If this change to the diff is ok with you too, I'll see that it gets committed. - Giorgos