Skip to content

Commit

Permalink
unix-socket: remove stale socket before calling chdir()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Jul 21, 2014
1 parent 8c2cfa5 commit 2869b3e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unix-socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2869b3e

Please sign in to comment.