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 <karsten.blees@gmail.com> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 20, 2014 at 10:00 UTC
2869b3e5dabdd78b336455ad493951badd35279e
1 file changed
+2
-1
unix-socket.c
+2
-1
@@ -99,11 +99,12 @@ int unix_stream_listen(const char *path)
99
struct sockaddr_un sa;
100
struct unix_sockaddr_context ctx;
101
102
+ unlink(path);
103
+
104
if (unix_sockaddr_init(&sa, path, &ctx) < 0)
105
return -1;
106
fd = unix_stream_socket();
107
106
- unlink(path);
108
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
109
goto fail;
110