Skip to content

Commit 962c38e

Browse files
carlosmngitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 889d358 commit 962c38e

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

builtin/config.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ static int show_config(const char *key_, const char *value_, void *cb)
129129
else
130130
sprintf(value, "%d", v);
131131
} else if (types == TYPE_PATH) {
132-
git_config_pathname(&vptr, key_, value_);
132+
if (git_config_pathname(&vptr, key_, value_) < 0)
133+
return -1;
133134
must_free_vptr = 1;
134135
} else if (value_) {
135136
vptr = value_;

t/t1300-repo-config.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,11 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' '
803803
test_cmp expect result
804804
'
805805

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+
806811
cat > expect << EOF
807812
[quote]
808813
leading = " test"

0 commit comments

Comments
 (0)