path: root/builtin/config.c
diff options
authorCarlos Martín Nieto <>2012-11-15 18:10:01 (GMT)
committerJunio C Hamano <>2012-11-16 02:12:17 (GMT)
commit962c38eedd931a608b5e675f12a21569d9f4d39f (patch)
treee5c46cb797bf1d26020a9350050d54ce9797e8ac /builtin/config.c
parent889d35899ba64640e47798681ecb34a4be043bad (diff)
config: don't segfault when given --path with a missing value
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. Detect the error and return immediately to avoid freeing or accessing the uninitialed memory in the stack. Signed-off-by: Carlos Martín Nieto <> Acked-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/config.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 8cd08da..a8cf1af 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -129,7 +129,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
sprintf(value, "%d", v);
} else if (types == TYPE_PATH) {
- git_config_pathname(&vptr, key_, value_);
+ if (git_config_pathname(&vptr, key_, value_) < 0)
+ return -1;
must_free_vptr = 1;
} else if (value_) {
vptr = value_;