NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/22522 (connect(2) may fail with EINVAL which isn't undocumented.)



The following reply was made to PR kern/22522; it has been noted by GNATS.

From: mlelstv%serpens.de@localhost (Michael van Elst)
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/22522 (connect(2) may fail with EINVAL which isn't undocumented.)
Date: Sun, 27 Sep 2026 10:46:31 -0000 (UTC)

 riastradh%NetBSD.org@localhost writes:
 
 >Synopsis: connect(2) may fail with EINVAL which isn't undocumented.
 
 >This was actually not really addressed.  If you don't trash len (e.g.,
 >use a local variable `int optlen' for the socket option length), and if
 >you add a case for EALREADY to continue the loop, you hit two problems:
 
 >1. Eventually, connect() fails with EINVAL.
 >2. getsockopt(SO_ERROR) _does not_ return ECONNREFUSED after that.
 
 
 tcp_connect() and other protocol functions will return EINVAL
 when the inpcb is detached. A refused connection will close the
 TCP session and detach the inpcb.
 
 In earlier code, this already happened in tcp_usrreq(), e.g.:
 
 https://github.com/dank101/4.4BSD-Lite2/blob/master/sys/netinet/tcp_usrreq.c#L116
 
 
 FreeBSD keeps the inpcb until the socket is freed and the protocol
 is detached. Until then the tcpcb also exists and when in disconnected
 state causes ECONNREFUSED to be returned.
 



Home | Main Index | Thread Index | Old Index