summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2014-07-20 08:00:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-07-21 16:38:07 (GMT)
commit2869b3e5dabdd78b336455ad493951badd35279e (patch)
treeeeab7281991666c46f163c19bb205038b6c01ee4
parent8c2cfa55446f542454eb4acc7f49d1747e425c94 (diff)
downloadgit-2869b3e5dabdd78b336455ad493951badd35279e.zip
git-2869b3e5dabdd78b336455ad493951badd35279e.tar.gz
git-2869b3e5dabdd78b336455ad493951badd35279e.tar.bz2
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>
-rw-r--r--unix-socket.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/unix-socket.c b/unix-socket.c
index 01f119f..91bd6b8 100644
--- a/unix-socket.c
+++ b/unix-socket.c
@@ -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;