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

[PATCH 2/2] handle_path_include: don't look at NULL value

From
Jeff King <peff@peff.net>
Date
Jan 28, 2014, 01:37 UTC
Message-ID
<20140128013729.GA21120@sigill.intra.peff.net>
In-Reply-To
<20140128013612.GA29548@sigill.intra.peff.net>
When we see config like:
  [include]
  path

the expand_user_path helper notices that the config value is empty, but we then dereference NULL while printing the error message (glibc will helpfully print "(null)" for us here, but we cannot rely on that).

  $ git -c include.path rev-parse
  error: Could not expand include path '(null)'
  fatal: unable to parse command-line config

Instead of tweaking our message, let's actually use config_error_nonbool to match other config variables that expect a value:

  $ git -c include.path rev-parse
  error: Missing value for 'include.path'
  fatal: unable to parse command-line config
Signed-off-by: Jeff King <peff@peff.net>
---
 config.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/config.c b/config.c
index d969a5a..314d8ee 100644
--- a/config.c
+++ b/config.c
@@ -84,8 +84,12 @@ static int handle_path_include(const char *path, struct config_include_data *inc
 {
 	int ret = 0;
 	struct strbuf buf = STRBUF_INIT;
-	char *expanded = expand_user_path(path);
+	char *expanded;
 
+	if (!path)
+		return config_error_nonbool("include.path");
+
+	expanded = expand_user_path(path);
 	if (!expanded)
 		return error("Could not expand include path '%s'", path);
 	path = expanded;
-- 
1.8.5.2.500.g8060133
Previous: Jeff King
Message 2 of 2 in “expand_user_path: do not look at NULL path”
  1. 1/2 expand_user_path: do not look at NULL pathJeff King, Jan 28, 2014
  2. 2/2 handle_path_include: don't look at NULL valueJeff King, Jan 28, 2014

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.