From arnej@europe.yahoo-inc.com  Tue May  3 18:35:24 2005
Return-Path: <arnej@europe.yahoo-inc.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id CAF7C16A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  3 May 2005 18:35:24 +0000 (GMT)
Received: from midten.trondheim.corp.yahoo.com (midten.trondheim.corp.yahoo.com [217.144.236.68])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9BBE843D5E
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  3 May 2005 18:35:23 +0000 (GMT)
	(envelope-from arnej@europe.yahoo-inc.com)
Received: from guinness.trondheim.corp.yahoo.com (guinness.trondheim.corp.yahoo.com [172.24.94.149])
	by midten.trondheim.corp.yahoo.com (8.12.10/8.12.10) with ESMTP id j43IZDd2046723
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 3 May 2005 20:35:13 +0200 (CEST)
	(envelope-from arnej@europe.yahoo-inc.com)
Received: from guinness.trondheim.corp.yahoo.com (localhost [127.0.0.1])
	by guinness.trondheim.corp.yahoo.com (8.12.9p2/8.12.9) with ESMTP id j43IZ7Tx064032
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 3 May 2005 20:35:08 +0200 (CEST)
	(envelope-from arnej@guinness.trondheim.corp.yahoo.com)
Received: (from arnej@localhost)
	by guinness.trondheim.corp.yahoo.com (8.12.9p2/8.12.9/Submit) id j43IZ7at064031;
	Tue, 3 May 2005 20:35:07 +0200 (CEST)
	(envelope-from arnej)
Message-Id: <200505031835.j43IZ7at064031@guinness.trondheim.corp.yahoo.com>
Date: Tue, 3 May 2005 20:35:07 +0200 (CEST)
From: Arne H Juul <arnej@europe.yahoo-inc.com>
Reply-To: Arne H Juul <arnej@europe.yahoo-inc.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: accept(2) can return EINVAL for undocumented reason
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         80587
>Category:       docs
>Synopsis:       [patch] accept(2) can return EINVAL for undocumented reason
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    remko
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 03 18:40:01 GMT 2005
>Closed-Date:    Sat Aug 20 08:39:20 GMT 2005
>Last-Modified:  Sat Aug 20 08:39:20 GMT 2005
>Originator:     Arne H Juul
>Release:        FreeBSD 4.9-RC-BUILDENV-OVERTURE i386
>Organization:
Yahoo!
>Environment:
System: FreeBSD guinness.trondheim.corp.yahoo.com 4.9-RC-BUILDENV-OVERTURE FreeBSD 4.9-RC-BUILDENV-OVERTURE #0: Sun Oct 12 21:33:45 CEST 2003 arnej@guinness.dev.trd.p4pnet.net:/usr/src/sys/compile/GUINNESS i386

	seen in everything from 4.9 to -current.
	
>Description:

	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().

>How-To-Repeat:
	
	man 2 accept

>Fix:

Index: lib/libc/sys/accept.2
===================================================================
RCS file: /usr/cvs/src/lib/libc/sys/accept.2,v
retrieving revision 1.30
diff -u -r1.30 accept.2
--- lib/libc/sys/accept.2	2 Jul 2004 23:52:13 -0000	1.30
+++ lib/libc/sys/accept.2	3 May 2005 18:25:35 -0000
@@ -154,6 +154,10 @@
 .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.
 .It Bq Er EFAULT
 The
 .Fa addr

>Release-Note:
>Audit-Trail:

From: Giorgos Keramidas <keramida@freebsd.org>
To: Arne H Juul <arnej@europe.yahoo-inc.com>
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 <arnej@europe.yahoo-inc.com> 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
 
Responsible-Changed-From-To: freebsd-bugs->freebsd-doc 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed May 4 01:24:39 GMT 2005 
Responsible-Changed-Why:  
Patch provided is against the documentation, not the kernel. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80587 

From: Arne H Juul <arnej@europe.yahoo-inc.com>
To: Giorgos Keramidas <keramida@freebsd.org>
Cc: bug-followup@freebsd.org
Subject: Re: kern/80587: accept(2) can return EINVAL for undocumented reason
Date: Wed, 4 May 2005 08:59:02 +0200 (CEST)

 On Wed, 4 May 2005, Giorgos Keramidas wrote:
 > 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.
 
 This is just a style thing, and personally I don't really mind
 either way; other system call man pages have separate paragraphs
 for same errno with different reasons, so I think it's best
 to follow that style.
 
 -- 
 Arne H Juul                       Mail:  arnej@europe.yahoo-inc.com
 Release engineer                  Web:   http://www.yahoo.com/
 Yahoo Norway                      Phone: +47 7320 1219
 Prinsensgate 49, 7013 Trondheim   Fax:   +47 7320 1201
State-Changed-From-To: open->closed 
State-Changed-By: keramida 
State-Changed-When: Wed May 4 11:09:32 GMT 2005 
State-Changed-Why:  
The original diff has been committed to CURRENT.  In a few days I'll merge 
this to -STABLE versions. 

Thanks :) 


Responsible-Changed-From-To: freebsd-doc->keramida 
Responsible-Changed-By: keramida 
Responsible-Changed-When: Wed May 4 11:09:32 GMT 2005 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=80587 
State-Changed-From-To: closed->patched 
State-Changed-By: keramida 
State-Changed-When: Wed May 4 11:10:49 GMT 2005 
State-Changed-Why:  
Keep this open (as 'patched') until I merge it to STABLE. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80587 
State-Changed-From-To: patched->closed 
State-Changed-By: remko 
State-Changed-When: Sat Aug 20 08:38:09 GMT 2005 
State-Changed-Why:  
I merged it to RELENG_5 per request of rionda. Also make sure 
that I get a pointyhat if something goes wrong instead of 
keramida. 


Responsible-Changed-From-To: keramida->remko 
Responsible-Changed-By: remko 
Responsible-Changed-When: Sat Aug 20 08:38:09 GMT 2005 
Responsible-Changed-Why:  
I merged it to RELENG_5 per request of rionda. Also make sure 
that I get a pointyhat if something goes wrong instead of 
keramida. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80587 
>Unformatted:
