Commit 56c95cf6fb4c6af6ae4ec43460dad09159c4700d

Philip Kelley 2020-05-10T21:43:38

Fix uninitialized stack memory and NULL ptr dereference in stash_to_index Caught by static analysis.

diff --git a/src/stash.c b/src/stash.c
index 4a13d05..790f56f 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -173,7 +173,7 @@ static int stash_to_index(
 	git_index *index,
 	const char *path)
 {
-	git_index *repo_index;
+	git_index *repo_index = NULL;
 	git_index_entry entry = {{0}};
 	struct stat st;
 	int error;
@@ -187,7 +187,7 @@ static int stash_to_index(
 		return error;
 
 	git_index_entry__init_from_stat(&entry, &st,
-		(repo_index != NULL || !repo_index->distrust_filemode));
+		(repo_index == NULL || !repo_index->distrust_filemode));
 
 	entry.path = path;