Web lists-archives.com

[GSoC][PATCH/RFC v3 3/3] credential-cache: only use user_socket if a socket




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@xxxxxxxxx>
---
 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