git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] revision.c: fix possible null pointer access
@ 2015-12-03 19:32 Stefan Naewe
  2015-12-03 20:06 ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Naewe @ 2015-12-03 19:32 UTC (permalink / raw)
  To: git; +Cc: Stefan Naewe

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 <stefan.naewe@gmail.com>
---
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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2015-12-07 21:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 19:32 [PATCH] revision.c: fix possible null pointer access Stefan Naewe
2015-12-03 20:06 ` Junio C Hamano
2015-12-03 21:15   ` Stefan Naewe
2015-12-03 21:34   ` Philip Oakley
2015-12-03 22:17     ` Stefan Beller
2015-12-04 15:39     ` Junio C Hamano
2015-12-04 23:32       ` Jeff King
2015-12-05 15:27   ` [PATCH v2] " Stefan Naewe
2015-12-07 20:31     ` Junio C Hamano
2015-12-07 21:54       ` Johannes Sixt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).