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

[PATCH] config: don't segfault when given --path with a missing value

From
Carlos Martín Nieto <cmn@elego.de>
Date
Nov 14, 2012, 04:50 UTC
Message-ID
<1352868604-20459-1-git-send-email-cmn@elego.de>

When given a variable without a value, such as '[section] var' and asking git-config to treat it as a path, git_config_pathname returns an error and doesn't modify its output parameter. show_config assumes that the call is always successful and sets a variable to indicate that vptr should be freed. In case of an error however, trying to do this will cause the program to be killed, as it's pointing to memory in the stack.

Set the must_free_vptr flag depending on the return value of
git_config_pathname so it's accurate.
---
 builtin/config.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/builtin/config.c b/builtin/config.c
index 442ccc2..60220d5 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -129,8 +129,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
 		else
 			sprintf(value, "%d", v);
 	} else if (types == TYPE_PATH) {
-		git_config_pathname(&vptr, key_, value_);
-		must_free_vptr = 1;
+		must_free_vptr = !git_config_pathname(&vptr, key_, value_);
 	} else if (value_) {
 		vptr = value_;
 	} else {
-- 
1.8.0.316.g291341c
Next: Jeff King
Message 1 of 6 in “config: don't segfault when given --path with a missing value”
  1. config: don't segfault when given --path with a missing valueCarlos Martín Nieto, Nov 14, 2012
  2. Jeff KingNov 15, 2012
  3. Jeff KingNov 15, 2012
  4. Jeff KingNov 15, 2012
  5. config: don't segfault when given --path with a missing valueCarlos Martín Nieto, Nov 15, 2012
  6. Jeff KingNov 15, 2012

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.