kern/80587: accept(2) can return EINVAL for undocumented reason

Arne H Juul arnej at
Tue May 3 11:40:08 PDT 2005

>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
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 03 18:40:01 GMT 2005
>Originator:     Arne H Juul
>Release:        FreeBSD 4.9-RC-BUILDENV-OVERTURE i386
System: FreeBSD 4.9-RC-BUILDENV-OVERTURE FreeBSD 4.9-RC-BUILDENV-OVERTURE #0: Sun Oct 12 21:33:45 CEST 2003 arnej at i386

	seen in everything from 4.9 to -current.

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

	man 2 accept


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 @@
 .Xr listen 2
 has not been called on the socket descriptor.
+.Fa addrlen
+argument is negative.
 .Fa addr


More information about the freebsd-bugs mailing list