From 6af6c5e59a9b522294c3a83a3efb0eccc1211087 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 6 Nov 2022 16:07:21 +0100 Subject: [PATCH] src/socket_wrapper.c: don't leak unlink() errno (most likely ENOENT) in swrap_bind() This fixes a problem hit by 'nsupdate -g' from the bind9-dnsutils 1:9.18.1-1ubuntu1.2 package. Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- src/socket_wrapper.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index 4c03e1c..14bd97a 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -4144,6 +4144,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) }; struct socket_info *si = find_socket_info(s); struct swrap_sockaddr_buf buf = {}; + int ret_errno = errno; int bind_error = 0; #if 0 /* FIXME */ bool in_use; @@ -4201,7 +4202,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) } if (bind_error != 0) { - errno = bind_error; + ret_errno = bind_error; ret = -1; goto out; } @@ -4225,17 +4226,21 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) 1, &si->bcast); if (ret == -1) { + ret_errno = errno; goto out; } unlink(un_addr.sa.un.sun_path); ret = libc_bind(s, &un_addr.sa.s, un_addr.sa_socklen); + if (ret == -1) { + ret_errno = errno; + } SWRAP_LOG(SWRAP_LOG_TRACE, - "bind(%s) path=%s, fd=%d", + "bind(%s) path=%s, fd=%d ret=%d ret_errno=%d", swrap_sockaddr_string(&buf, myaddr), - un_addr.sa.un.sun_path, s); + un_addr.sa.un.sun_path, s, ret, ret_errno); if (ret == 0) { si->bound = 1; @@ -4243,7 +4248,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) out: SWRAP_UNLOCK_SI(si); - + errno = ret_errno; return ret; } -- 2.34.1