From 0de1633783685e9fb1943551217cdda7edbd245b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 24 Oct 2011 17:36:09 +1100 Subject: tree-walk.c: do not leak internal structure in tree_entry_len() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- tree-walk.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tree-walk.h') diff --git a/tree-walk.h b/tree-walk.h index 0089581e1d..884d01ac33 100644 --- a/tree-walk.h +++ b/tree-walk.h @@ -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); -- cgit v1.2.1