Commit a137cdbd90bb096dc8fc21966bb2e25d424b4e74

Etienne Samson 2018-04-18T21:41:44

refspec: check for valid parameters in git_refspec__dwim_one CID:1383993, "In git_refspec__dwim_one: All paths that lead to this null pointer comparison already dereference the pointer earlier (CWE-476)"

diff --git a/src/refspec.c b/src/refspec.c
index 01a77c9..943a9c7 100644
--- a/src/refspec.c
+++ b/src/refspec.c
@@ -304,6 +304,7 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
 	git_buf buf = GIT_BUF_INIT;
 	size_t j, pos;
 	git_remote_head key;
+	git_refspec *cur;
 
 	const char* formatters[] = {
 		GIT_REFS_DIR "%s",
@@ -312,7 +313,9 @@ int git_refspec__dwim_one(git_vector *out, git_refspec *spec, git_vector *refs)
 		NULL
 	};
 
-	git_refspec *cur = git__calloc(1, sizeof(git_refspec));
+	assert(out && spec && refs);
+
+	cur = git__calloc(1, sizeof(git_refspec));
 	GITERR_CHECK_ALLOC(cur);
 
 	cur->force = spec->force;