[GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket
- From
Devin Lehmacher <lehmacdj@gmail.com>
- Date
- Mar 14, 2017, 00:32 UTC
- Message-ID
- <20170314003246.71586-4-lehmacdj@gmail.com>
- In-Reply-To
- <20170314003246.71586-1-lehmacdj@gmail.com>
Create function is_socket. Make get_socket_path return check if ~/.git-credential-cache/socket is a socket and not just a file. If file_exists behavior could change in an unexpected way. Additionally a file at ~/.git-credential-cache/socket could cause false positives which would otherwise lead to crashes.
Signed-off-by: Devin Lehmacher <lehmacdj@gmail.com> --- credential-cache.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/credential-cache.c b/credential-cache.c index db1343b46..63236adc2 100644 --- a/credential-cache.c +++ b/credential-cache.c @@ -83,12 +83,18 @@ static void do_cache(const char *socket, const char *action, int timeout, strbuf_release(&buf); } +static int is_socket(char *path) { + struct stat sb; + int ret = lstat(path, &sb); + return ret && S_IFSOCK(sb.st_mode); +} + static char *get_socket_path(void) { char *home_socket; home_socket = expand_user_path("~/.git-credential-cache/socket"); if (home_socket) { - if (file_exists(home_socket)) + if (is_socket(home_socket)) return home_socket; else free(home_socket);
-- 2.11.0