mirror of
https://github.com/esphome/esphome.git
synced 2026-07-10 17:05:36 +00:00
[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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user