summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-07-31 04:38:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-08-01 20:06:40 (GMT)
commit37806080d7be1ab5b2fa918f6a528652596ea2c1 (patch)
treefb6f260202b9ef1feba1dac3a67d36aeb2ef98e9 /unpack-trees.c
parent9055384710dd8963b125f4f87c24d8f67d9fa24f (diff)
downloadgit-37806080d7be1ab5b2fa918f6a528652596ea2c1.zip
git-37806080d7be1ab5b2fa918f6a528652596ea2c1.tar.gz
git-37806080d7be1ab5b2fa918f6a528652596ea2c1.tar.bz2
tree-walk: use size_t consistently
We store and manipulate the cumulative traverse_info.pathlen as an "int", which can overflow when we are fed ridiculously long pathnames (e.g., ones at the edge of 2GB or 4GB, even if the individual tree entry names are smaller than that). The results can be confusing, though after some prodding I was not able to use this integer overflow to cause an under-allocated buffer. Let's consistently use size_t to generate and store these, and make sure our addition doesn't overflow. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 26f971f..8dbfb22 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -686,7 +686,7 @@ static int index_pos_by_traverse_info(struct name_entry *names,
struct traverse_info *info)
{
struct unpack_trees_options *o = info->data;
- int len = traverse_path_len(info, names);
+ size_t len = traverse_path_len(info, names);
char *name = xmalloc(len + 1 /* slash */ + 1 /* NUL */);
int pos;
@@ -814,7 +814,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
newinfo.name = p->path;
newinfo.namelen = p->pathlen;
newinfo.mode = p->mode;
- newinfo.pathlen += tree_entry_len(p) + 1;
+ newinfo.pathlen = st_add3(newinfo.pathlen, tree_entry_len(p), 1);
newinfo.df_conflicts |= df_conflicts;
/*
@@ -960,7 +960,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info,
struct index_state *istate,
int is_transient)
{
- int len = traverse_path_len(info, n);
+ size_t len = traverse_path_len(info, n);
struct cache_entry *ce =
is_transient ?
make_empty_transient_cache_entry(len) :