diff options
| author | K Jayatheerth <jayatheerthkulkarni2005@gmail.com> | 2026-03-04 18:35:01 +0530 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-03-04 09:06:30 -0800 |
| commit | 61d0b79e4c2dffa27c89b409aaa084deb0ed2172 (patch) | |
| tree | 3914c735dc01181175e8fd8b66f96e32c7ed4d74 | |
| parent | 99a626f479781da77ea41f356bd35a27af8ec11b (diff) | |
| download | git-61d0b79e4c2dffa27c89b409aaa084deb0ed2172.tar.xz | |
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>
| -rw-r--r-- | path.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -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'); } |
