git/list[1] front-page[2] threads[3] people[4] search[5] about
 

NULL dereference in ab/wildmatch

From
Jeff King <peff@peff.net>
Date
Jun 25, 2017, 14:09 UTC
Message-ID
<20170625140957.kjkctkaesm6il5u2@sigill.intra.peff.net>
On Sun, Jun 25, 2017 at 02:50:10AM -0700, scan-admin@coverity.com wrote:
Show 22 quoted lines
> 
> ** CID 1413016:  Null pointer dereferences  (FORWARD_NULL)
> /config.c: 213 in include_by_gitdir()
> 
> 
> ________________________________________________________________________________________________________
> *** CID 1413016:  Null pointer dereferences  (FORWARD_NULL)
> /config.c: 213 in include_by_gitdir()
> 207     {
> 208     	struct strbuf text = STRBUF_INIT;
> 209     	struct strbuf pattern = STRBUF_INIT;
> 210     	int ret = 0, prefix;
> 211     	const char *git_dir;
> 212     	int already_tried_absolute = 0;
> >>>     CID 1413016:  Null pointer dereferences  (FORWARD_NULL)
> >>>     Assigning: "code" = "NULL".
> 213     	struct wildmatch_compiled *code = NULL;
> 214     
> 215     	if (opts->git_dir)
> 216     		git_dir = opts->git_dir;
> 217     	else
> 218     		goto done;

I think this comes the "goto done" at the bottom of the context. After that label, we call wildmatch_free() unconditionally. Probably it just needs:

diff --git a/config.c b/config.c
index 515f8518e2..cfee92ebbf 100644
--- a/config.c
+++ b/config.c
@@ -260,7 +260,8 @@ static int include_by_gitdir(const struct config_options *opts,
 done:
 	strbuf_release(&pattern);
 	strbuf_release(&text);
-	wildmatch_free(code);
+	if (code)
+		wildmatch_free(code);
 	return ret;
 }
 

though arguably wildmatch_free() should be taught to handle NULL.

-Peff
Next: Ævar Arnfjörð Bjarmason
Message 1 of 2 in “NULL dereference in ab/wildmatch”
  1. Jeff KingJun 25, 2017
  2. Ævar Arnfjörð BjarmasonJun 25, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.