Skip to content

Commit 2869b3e

Browse files
rscharfegitster
authored andcommitted
unix-socket: remove stale socket before calling chdir()
unix_stream_listen() is given a path. It calls unix_sockaddr_init(), which in turn can call chdir(). After that a relative path doesn't mean the same as before. Any use of the original path should thus happen before that call. For that reason, unlink the given path (to get rid of a possibly existing stale socket) right at the beginning of the function. Noticed-by: Karsten Blees <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8c2cfa5 commit 2869b3e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

unix-socket.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ int unix_stream_listen(const char *path)
9999
struct sockaddr_un sa;
100100
struct unix_sockaddr_context ctx;
101101

102+
unlink(path);
103+
102104
if (unix_sockaddr_init(&sa, path, &ctx) < 0)
103105
return -1;
104106
fd = unix_stream_socket();
105107

106-
unlink(path);
107108
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
108109
goto fail;
109110

0 commit comments

Comments
 (0)