Commit bd0a55162d4196a04e77e68dc039f9ded3efff1a

Boris Egorov 2015-01-25T00:07:23

pathspec: do not try to dereference NULL pathspec_match_free() should not dereference a NULL passed to it. I found this issue when I tried to run example log program with nonexistent branch: ./example/log help Such call leads to segmentation fault.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/src/pathspec.c b/src/pathspec.c
index 8b469f7..6aef574 100644
--- a/src/pathspec.c
+++ b/src/pathspec.c
@@ -296,6 +296,9 @@ int git_pathspec_matches_path(
 
 static void pathspec_match_free(git_pathspec_match_list *m)
 {
+	if (!m)
+		return;
+
 	git_pathspec_free(m->pathspec);
 	m->pathspec = NULL;