]> granicus.if.org Git - git/commitdiff
unix-socket: remove stale socket before calling chdir()
authorRené Scharfe <l.s.r@web.de>
Sun, 20 Jul 2014 08:00:41 +0000 (10:00 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 21 Jul 2014 16:38:07 +0000 (09:38 -0700)
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>
unix-socket.c

index 01f119f9700791ddc59a81cdc80fd365e678622a..91bd6b89d4946bbd80a0b9e9e7d6af21d6a2f61a 100644 (file)
@@ -99,11 +99,12 @@ int unix_stream_listen(const char *path)
        struct sockaddr_un sa;
        struct unix_sockaddr_context ctx;
 
+       unlink(path);
+
        if (unix_sockaddr_init(&sa, path, &ctx) < 0)
                return -1;
        fd = unix_stream_socket();
 
-       unlink(path);
        if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
                goto fail;