Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct socket state checks and handle listen errors in netsyscall #2068

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/net/netsyscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,12 @@ static sysreturn netsock_listen(struct sock *sock, int backlog)
}
goto unlock_out;
}
struct tcp_pcb * lw = tcp_listen_with_backlog(s->info.tcp.lw, backlog);
err_t err;
struct tcp_pcb * lw = tcp_listen_with_backlog_and_err(s->info.tcp.lw, backlog, &err);
if (!lw) {
rv = lwip_to_errno(err);
goto unlock_out;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, if the SO_REUSEADDR socket option is enabled, the bind() system call doesn't return -EADDRINUSE if another socket is bound to the same address, so we have to check for in-use addresses in the listen() system call. This is the correct fix.

tcp_unref(s->info.tcp.lw);
tcp_ref(lw);
s->info.tcp.lw = lw;
Expand Down