From b0adc7bf978d764bffd22af0697cff90e49a62a5 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sat, 29 Jul 2017 21:38:34 +0100 Subject: [PATCH] librb: commio: Must set addrlen before every call to accept() If an IPv4 connection is dropped by the pre-callback, and there is a pending IPv6 connection on the same listening socket then the retried accept() will be unable to populate `st` because `addrlen` will be too small. Also initialise `st` each time to avoid a clang static analysis warning. --- librb/src/commio.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/librb/src/commio.c b/librb/src/commio.c index 945c0a77..f8bd8fa5 100644 --- a/librb/src/commio.c +++ b/librb/src/commio.c @@ -346,11 +346,14 @@ rb_accept_tryaccept(rb_fde_t *F, void *data) { struct rb_sockaddr_storage st; rb_fde_t *new_F; - rb_socklen_t addrlen = sizeof(st); + rb_socklen_t addrlen; int new_fd; while(1) { + memset(&st, 0, sizeof(st)); + addrlen = sizeof(st); + new_fd = accept(F->fd, (struct sockaddr *)&st, &addrlen); rb_get_errno(); if(new_fd < 0) @@ -752,9 +755,6 @@ mangle_mapped_sockaddr(struct sockaddr *in) { struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)in; - if(in->sa_family == AF_INET) - return; - if(in->sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr)) { struct sockaddr_in in4; @@ -764,7 +764,6 @@ mangle_mapped_sockaddr(struct sockaddr *in) in4.sin_addr.s_addr = ((uint32_t *)&in6->sin6_addr)[3]; memcpy(in, &in4, sizeof(struct sockaddr_in)); } - return; } #endif