mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
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>
This commit is contained in:
committed by
Junio C Hamano
parent
9055384710
commit
37806080d7
@@ -60,7 +60,7 @@ struct traverse_info {
|
||||
size_t namelen;
|
||||
unsigned mode;
|
||||
|
||||
int pathlen;
|
||||
size_t pathlen;
|
||||
struct pathspec *pathspec;
|
||||
|
||||
unsigned long df_conflicts;
|
||||
@@ -74,9 +74,9 @@ char *make_traverse_path(char *path, const struct traverse_info *info,
|
||||
const char *name, size_t namelen);
|
||||
void setup_traverse_info(struct traverse_info *info, const char *base);
|
||||
|
||||
static inline int traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
|
||||
static inline size_t traverse_path_len(const struct traverse_info *info, const struct name_entry *n)
|
||||
{
|
||||
return info->pathlen + tree_entry_len(n);
|
||||
return st_add(info->pathlen, tree_entry_len(n));
|
||||
}
|
||||
|
||||
/* in general, positive means "kind of interesting" */
|
||||
|
||||
Reference in New Issue
Block a user