From 99a626f479781da77ea41f356bd35a27af8ec11b Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Wed, 4 Mar 2026 18:35:00 +0530 Subject: [PATCH 1/3] path: remove unused header The "environment.h" header is included in "path.c", but none of the functions or macros it provides are used in this file. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 1 - 1 file changed, 1 deletion(-) diff --git a/path.c b/path.c index d726537622..f613d8bbd1 100644 --- a/path.c +++ b/path.c @@ -4,7 +4,6 @@ #include "git-compat-util.h" #include "abspath.h" -#include "environment.h" #include "gettext.h" #include "repository.h" #include "strbuf.h" From 61d0b79e4c2dffa27c89b409aaa084deb0ed2172 Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Wed, 4 Mar 2026 18:35:01 +0530 Subject: [PATCH 2/3] path: use size_t for dir_prefix length The strlen() function returns a size_t. Storing this in a standard signed int is a bad practice that invites overflow vulnerabilities if paths get absurdly long. Switch the variable to size_t. This is safe to do because 'len' is strictly used as an argument to strncmp() (which expects size_t) and as a positive array index, involving no signed arithmetic that could rely on negative values. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index f613d8bbd1..56be5e1726 100644 --- a/path.c +++ b/path.c @@ -58,7 +58,7 @@ static void strbuf_cleanup_path(struct strbuf *sb) static int dir_prefix(const char *buf, const char *dir) { - int len = strlen(dir); + size_t len = strlen(dir); return !strncmp(buf, dir, len) && (is_dir_sep(buf[len]) || buf[len] == '\0'); } From b22ed4c4f9667d400744d0ab013745720d91b8d4 Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Wed, 4 Mar 2026 18:35:02 +0530 Subject: [PATCH 3/3] path: remove redundant function calls repo_settings_get_shared_repository() is invoked multiple times in calc_shared_perm(). While the function internally caches the value, repeated calls still add unnecessary noise. Store the result in a local variable and reuse it instead. This makes it explicit that the value is expected to remain constant and avoids repeated calls in the same scope. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/path.c b/path.c index 56be5e1726..5cd38b2a16 100644 --- a/path.c +++ b/path.c @@ -741,18 +741,18 @@ int calc_shared_perm(struct repository *repo, int mode) { int tweak; - - if (repo_settings_get_shared_repository(repo) < 0) - tweak = -repo_settings_get_shared_repository(repo); + int shared_repo = repo_settings_get_shared_repository(repo); + if (shared_repo < 0) + tweak = -shared_repo; else - tweak = repo_settings_get_shared_repository(repo); + tweak = shared_repo; if (!(mode & S_IWUSR)) tweak &= ~0222; if (mode & S_IXUSR) /* Copy read bits to execute bits */ tweak |= (tweak & 0444) >> 2; - if (repo_settings_get_shared_repository(repo) < 0) + if (shared_repo < 0) mode = (mode & ~0777) | tweak; else mode |= tweak;