diff options
author | Stefan Metzmacher <metze@samba.org> | 2020-02-27 16:47:35 +0000 |
---|---|---|
committer | Andreas Schneider <asn@samba.org> | 2020-03-19 16:50:09 +0100 |
commit | 7a9f807302e0ddb1579b5db2c3772bb23f44b04e (patch) | |
tree | 4b78884835493802c934e846fe2c7c71dac546b6 /src | |
parent | d23452ba4ec64c5be89864a8bd31d6ee2053be46 (diff) | |
download | socket_wrapper-7a9f807302e0ddb1579b5db2c3772bb23f44b04e.tar.gz socket_wrapper-7a9f807302e0ddb1579b5db2c3772bb23f44b04e.tar.xz socket_wrapper-7a9f807302e0ddb1579b5db2c3772bb23f44b04e.zip |
swrap: detect stale fd for socket(PF_UNIX) and accept()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/socket_wrapper.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c index b3e5713..31d12b7 100644 --- a/src/socket_wrapper.c +++ b/src/socket_wrapper.c @@ -1536,6 +1536,9 @@ static unsigned int socket_wrapper_default_iface(void) static void set_socket_info_index(int fd, int idx) { + SWRAP_LOG(SWRAP_LOG_TRACE, + "fd=%d idx=%d\n", + fd, idx); socket_fds_idx[fd] = idx; /* This builtin issues a full memory barrier. */ __sync_synchronize(); @@ -1543,6 +1546,9 @@ static void set_socket_info_index(int fd, int idx) static void reset_socket_info_index(int fd) { + SWRAP_LOG(SWRAP_LOG_TRACE, + "fd=%d idx=%d\n", + fd, -1); set_socket_info_index(fd, -1); } @@ -3141,7 +3147,15 @@ static int swrap_socket(int family, int type, int protocol) case AF_PACKET: #endif /* AF_PACKET */ case AF_UNIX: - return libc_socket(family, type, protocol); + fd = libc_socket(family, type, protocol); + if (fd != -1) { + /* Check if we have a stale fd and remove it */ + swrap_remove_stale(fd); + SWRAP_LOG(SWRAP_LOG_TRACE, + "Unix socket fd=%d", + fd); + } + return fd; default: errno = EAFNOSUPPORT; return -1; @@ -3385,6 +3399,9 @@ static int swrap_accept(int s, fd = ret; + /* Check if we have a stale fd and remove it */ + swrap_remove_stale(fd); + SWRAP_LOCK_SI(parent_si); ret = sockaddr_convert_from_un(parent_si, @@ -3667,6 +3684,9 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, } if (si->family != serv_addr->sa_family) { + SWRAP_LOG(SWRAP_LOG_ERROR, + "called for fd=%d (family=%d) called with invalid family=%d\n", + s, si->family, serv_addr->sa_family); errno = EINVAL; ret = -1; goto done; @@ -6077,6 +6097,7 @@ static int swrap_close(int fd) return libc_close(fd); } + SWRAP_LOG(SWRAP_LOG_TRACE, "Close wrapper for fd=%d", fd); reset_socket_info_index(fd); si = swrap_get_socket_info(si_index); |