src/socket_wrapper.c: don't leak unlink() errno (most likely ENOENT) in swrap_bind()
authorStefan Metzmacher <metze@samba.org>
Sun, 6 Nov 2022 15:07:21 +0000 (16:07 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 17 Jan 2023 15:19:47 +0000 (16:19 +0100)
This fixes a problem hit by 'nsupdate -g' from the
bind9-dnsutils 1:9.18.1-1ubuntu1.2 package.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
src/socket_wrapper.c

index 4c03e1cdd4984430c8d62681ed4b80d6035e74d6..14bd97a2d343c033bb8460fde6f68e35e4908c39 100644 (file)
@@ -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;
 }