From: K Jayatheerth Date: Wed, 4 Mar 2026 13:05:01 +0000 (+0530) Subject: path: use size_t for dir_prefix length X-Git-Tag: v2.54.0-rc0~89^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61d0b79e4c2dffa27c89b409aaa084deb0ed2172;p=thirdparty%2Fgit.git 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 --- 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'); }