[socket] Fix pre-existing bugs in LWIP raw TCP socket

Fix two pre-existing bugs found during review of #14398:

1. bind() returns 0 on nullptr name instead of -1, inconsistent with
   POSIX bind() semantics and can mask invalid calls.

2. listen() doesn't re-register tcp_err after tcp_listen_with_backlog
   reallocates the PCB. The error callback was set during init() on
   the original PCB which is now freed, leaving the new listen PCB
   without an error handler.
This commit is contained in:
J. Nick Koston
2026-03-01 07:22:27 -10:00
parent 5d9c3a0e71
commit cce95ff58c
@@ -68,7 +68,7 @@ int LWIPRawCommon::bind(const struct sockaddr *name, socklen_t addrlen) {
}
if (name == nullptr) {
errno = EINVAL;
return 0;
return -1;
}
ip_addr_t ip;
in_port_t port;
@@ -609,6 +609,7 @@ int LWIPRawListenImpl::listen(int backlog) {
LWIP_LOG("tcp_arg(%p)", this->pcb_);
tcp_arg(this->pcb_, this);
tcp_accept(this->pcb_, LWIPRawListenImpl::s_accept_fn);
tcp_err(this->pcb_, LWIPRawListenImpl::s_err_fn);
return 0;
}