kern/80587: accept(2) can return EINVAL for undocumented reason
Arne H Juul
arnej at europe.yahoo-inc.com
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
>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 at 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:
More information about the freebsd-bugs
mailing list