From 277a85d86b3bf7b9f1e05d6446b9bc5dadd73d83 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 21 Jul 2022 07:22:08 +0200 Subject: [PATCH] swrap: Fix a TOCTOU issue in swrap_auto_bind() Signed-off-by: Andreas Schneider --- src/socket_wrapper.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index ef87519..5804e93 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -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; } -- GitLab