Skip to content

Commit 2a0e114

Browse files
pks-tgitster
authored andcommitted
compat/fsmonitor: fix socket path in networked SHA256 repos
The IPC socket used by the fsmonitor on Darwin is usually contained in the Git repository itself. When the repository is hosted on a networked filesystem though, we instead create the socket path in the user's home directory or the socket directory. In that case, we derive the path by hashing the repository path. But while we always use SHA1 to hash the repository path, we then end up using `hash_to_hex()` to append the computed hash to the socket path. This is wrong because `hash_to_hex()` uses the hash algorithm configured in `the_repository`, which may not be SHA1. The consequence is that we may append uninitialized bytes to the path when operating in a SHA256 repository. Fix this bug by using `hash_to_hex_algop()` with SHA1. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 99cf4d6 commit 2a0e114

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compat/fsmonitor/fsm-ipc-darwin.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
1717
git_SHA_CTX sha1ctx;
1818
char *sock_dir = NULL;
1919
struct strbuf ipc_file = STRBUF_INIT;
20-
unsigned char hash[GIT_MAX_RAWSZ];
20+
unsigned char hash[GIT_SHA1_RAWSZ];
2121

2222
if (!r)
2323
BUG("No repository passed into fsmonitor_ipc__get_path");
@@ -41,9 +41,10 @@ const char *fsmonitor_ipc__get_path(struct repository *r)
4141
/* Create the socket file in either socketDir or $HOME */
4242
if (sock_dir && *sock_dir) {
4343
strbuf_addf(&ipc_file, "%s/.git-fsmonitor-%s",
44-
sock_dir, hash_to_hex(hash));
44+
sock_dir, hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
4545
} else {
46-
strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s", hash_to_hex(hash));
46+
strbuf_addf(&ipc_file, "~/.git-fsmonitor-%s",
47+
hash_to_hex_algop(hash, &hash_algos[GIT_HASH_SHA1]));
4748
}
4849
free(sock_dir);
4950

0 commit comments

Comments
 (0)