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-diff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tree-diff.c') diff --git a/tree-diff.c b/tree-diff.c index b3cc2e4753..6782484489 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -21,8 +21,8 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2, sha1 = tree_entry_extract(t1, &path1, &mode1); sha2 = tree_entry_extract(t2, &path2, &mode2); - pathlen1 = tree_entry_len(path1, sha1); - pathlen2 = tree_entry_len(path2, sha2); + pathlen1 = tree_entry_len(&t1->entry); + pathlen2 = tree_entry_len(&t2->entry); cmp = base_name_compare(path1, pathlen1, mode1, path2, pathlen2, mode2); if (cmp < 0) { show_entry(opt, "-", t1, base); @@ -85,7 +85,7 @@ static void show_entry(struct diff_options *opt, const char *prefix, unsigned mode; const char *path; const unsigned char *sha1 = tree_entry_extract(desc, &path, &mode); - int pathlen = tree_entry_len(path, sha1); + int pathlen = tree_entry_len(&desc->entry); int old_baselen = base->len; strbuf_add(base, path, pathlen); -- cgit v1.2.3