Skip to content

Commit

Permalink
socket: fix use of ERRNO_IS_DISCONNECT()
Browse files Browse the repository at this point in the history
Given that ERRNO_IS_DISCONNECT() also matches positive values,
make sure this macro is not called with arguments that do not have
errno semantics.

In this case the argument passed to ERRNO_IS_DISCONNECT() is the value
returned by socket_acquire_peer() which can legitimately return 1
without errno semantics, so fix this by moving ERRNO_IS_DISCONNECT()
invocation to the branch where the return value is known to be negative.
  • Loading branch information
ldv-alt committed Jul 16, 2023
1 parent ed3745b commit d5f8890
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2358,10 +2358,12 @@ static void socket_enter_running(Socket *s, int cfd_in) {

if (s->max_connections_per_source > 0) {
r = socket_acquire_peer(s, cfd, &p);
if (ERRNO_IS_DISCONNECT(r))
return;
if (r < 0) /* We didn't have enough resources to acquire peer information, let's fail. */
if (r < 0) {
if (ERRNO_IS_DISCONNECT(r))
return;
/* We didn't have enough resources to acquire peer information, let's fail. */
goto fail;
}
if (r > 0 && p->n_ref > s->max_connections_per_source) {
_cleanup_free_ char *t = NULL;

Expand Down

0 comments on commit d5f8890

Please sign in to comment.