Skip to content

Commit 61d0b79

Browse files
jayatheerthkulkarnigitster
authored andcommitted
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 <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 99a626f commit 61d0b79

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void strbuf_cleanup_path(struct strbuf *sb)
5858

5959
static int dir_prefix(const char *buf, const char *dir)
6060
{
61-
int len = strlen(dir);
61+
size_t len = strlen(dir);
6262
return !strncmp(buf, dir, len) &&
6363
(is_dir_sep(buf[len]) || buf[len] == '\0');
6464
}

0 commit comments

Comments
 (0)