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 <cmn@elego.de> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Carlos Martín Nieto committed
Nov 15, 2012 at 10:10 UTC
962c38eedd931a608b5e675f12a21569d9f4d39f
2 files changed
+7
-1
builtin/config.c
+2
-1
@@ -129,7 +129,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
129
else
130
sprintf(value, "%d", v);
131
} else if (types == TYPE_PATH) {
132
- git_config_pathname(&vptr, key_, value_);
132
+ if (git_config_pathname(&vptr, key_, value_) < 0)
133
+ return -1;
134
must_free_vptr = 1;
135
} else if (value_) {
136
vptr = value_;
t/t1300-repo-config.sh
+5
@@ -803,6 +803,11 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
803
test_cmp expect result
804
'
805
806
+test_expect_success 'get --path barfs on boolean variable' '
807
+ echo "[path]bool" >.git/config &&
808
+ test_must_fail git config --get --path path.bool
809
+'
810
+
811
cat > expect << EOF
812
[quote]
813
leading = " test"