| From 4e2897b63b034fbf1ce5e52e3fbf14184f2ef0f0 Mon Sep 17 00:00:00 2001 |
| From: Jeff King <peff@peff.net> |
| Date: Sun, 13 May 2018 12:09:42 -0400 |
| Subject: is_ntfs_dotgit: use a size_t for traversing string |
| |
| commit 11a9f4d807a0d71dc6eff51bb87baf4ca2cccf1d upstream. |
| |
| We walk through the "name" string using an int, which can |
| wrap to a negative value and cause us to read random memory |
| before our array (e.g., by creating a tree with a name >2GB, |
| since "int" is still 32 bits even on most 64-bit platforms). |
| Worse, this is easy to trigger during the fsck_tree() check, |
| which is supposed to be protecting us from malicious |
| garbage. |
| |
| Note one bit of trickiness in the existing code: we |
| sometimes assign -1 to "len" at the end of the loop, and |
| then rely on the "len++" in the for-loop's increment to take |
| it back to 0. This is still legal with a size_t, since |
| assigning -1 will turn into SIZE_MAX, which then wraps |
| around to 0 on increment. |
| |
| Signed-off-by: Jeff King <peff@peff.net> |
| Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> |
| --- |
| path.c | 2 +- |
| 1 file changed, 1 insertion(+), 1 deletion(-) |
| |
| diff --git a/path.c b/path.c |
| index 4c054037cc..2f12d8eac6 100644 |
| --- a/path.c |
| +++ b/path.c |
| @@ -1235,7 +1235,7 @@ static int only_spaces_and_periods(const char *path, size_t len, size_t skip) |
| |
| int is_ntfs_dotgit(const char *name) |
| { |
| - int len; |
| + size_t len; |
| |
| for (len = 0; ; len++) |
| if (!name[len] || name[len] == '\\' || is_dir_sep(name[len])) { |
| -- |
| 2.17.0.921.gf22659ad46 |
| |