swrap: Fix a TOCTOU issue in swrap_auto_bind()
authorAndreas Schneider <asn@samba.org>
Thu, 21 Jul 2022 05:22:08 +0000 (07:22 +0200)
committerAndreas Schneider <asn@samba.org>
Thu, 21 Jul 2022 12:43:55 +0000 (14:43 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
src/socket_wrapper.c

index ef87519a19c96e8fa7ba200185637e4ef8dc3f46..5804e936ff791953d040301a7a8106b004cd30ad 100644 (file)
@@ -3815,7 +3815,6 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
        char type;
        int ret;
        int port;
-       struct stat st;
        char *swrap_dir = NULL;
 
        swrap_mutex_lock(&autobind_start_mutex);
@@ -3916,10 +3915,12 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family)
                              type,
                              socket_wrapper_default_iface(),
                              port);
-               if (stat(un_addr.sa.un.sun_path, &st) == 0) continue;
 
                ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen);
                if (ret == -1) {
+                       if (errno == EALREADY || errno == EADDRINUSE) {
+                               continue;
+                       }
                        goto done;
                }