tree-walk.c: do not leak internal structure in tree_entry_len()
tree_entry_len() does not simply take two random arguments and return a tree length. The two pointers must point to a tree item structure, or struct name_entry. Passing random pointers will return incorrect value. Force callers to pass struct name_entry instead of two pointers (with hope that they don't manually construct struct name_entry themselves) Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
997a1946a5
commit
0de1633783
@@ -20,9 +20,9 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
|
||||
return desc->entry.sha1;
|
||||
}
|
||||
|
||||
static inline int tree_entry_len(const char *name, const unsigned char *sha1)
|
||||
static inline int tree_entry_len(const struct name_entry *ne)
|
||||
{
|
||||
return (const char *)sha1 - name - 1;
|
||||
return (const char *)ne->sha1 - ne->path - 1;
|
||||
}
|
||||
|
||||
void update_tree_entry(struct tree_desc *);
|
||||
@@ -58,7 +58,7 @@ extern 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)
|
||||
{
|
||||
return info->pathlen + tree_entry_len(n->path, n->sha1);
|
||||
return info->pathlen + tree_entry_len(n);
|
||||
}
|
||||
|
||||
extern int tree_entry_interesting(const struct name_entry *, struct strbuf *, int, const struct pathspec *ps);
|
||||
|
||||
Reference in New Issue
Block a user