Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 May 2005 20:35:07 +0200 (CEST)
From:      Arne H Juul <arnej@europe.yahoo-inc.com>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/80587: accept(2) can return EINVAL for undocumented reason
Message-ID:  <200505031835.j43IZ7at064031@guinness.trondheim.corp.yahoo.com>
Resent-Message-ID: <200505031840.j43Ie1cU044948@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         80587
>Category:       kern
>Synopsis:       accept(2) can return EINVAL for undocumented reason
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 03 18:40:01 GMT 2005
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:



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