[PATCH] revision.c: fix possible null pointer access
From: Stefan Naewe <hidden>
Date: 2016-06-15 23:07:22
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Stefan Naewe <hidden>
Date: 2016-06-15 23:07:22
Subsystem:
the rest · Maintainer:
Linus Torvalds
Two functions dereference a tree pointer before checking if the pointer is valid. Fix that by doing the check first. Signed-off-by: Stefan Naewe <redacted> --- This has been reported through the CppHints newsletter (http://cpphints.com/hints/40) but doesn't seem to have made its way to the ones who care (the git list that is...) revision.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 0fbb684..bb40179 100644
--- a/revision.c
+++ b/revision.c@@ -104,7 +104,12 @@ static void mark_tree_contents_uninteresting(struct tree *tree) { struct tree_desc desc; struct name_entry entry; - struct object *obj = &tree->object; + struct object *obj; + + if (!tree) + return; + + obj = &tree->object; if (!has_sha1_file(obj->sha1)) return;
@@ -135,10 +140,13 @@ static void mark_tree_contents_uninteresting(struct tree *tree) void mark_tree_uninteresting(struct tree *tree) { - struct object *obj = &tree->object; + struct object *obj; if (!tree) return; + + obj = &tree->object; + if (obj->flags & UNINTERESTING) return; obj->flags |= UNINTERESTING;
--
2.6.3