Skip to content

Commit f067a13

Browse files
jonasJunio C Hamano
authored andcommitted
repo-config: give value_ a sane default so regexec won't segfault
Signed-off-by: Jonas Fonseca <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa1dbc9 commit f067a13

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

repo-config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ static enum { T_RAW, T_INT, T_BOOL } type = T_RAW;
1414

1515
static int show_config(const char* key_, const char* value_)
1616
{
17+
if (value_ == NULL)
18+
value_ = "";
19+
1720
if (!strcmp(key_, key) &&
1821
(regexp == NULL ||
1922
(do_not_match ^
@@ -35,7 +38,7 @@ static int show_config(const char* key_, const char* value_)
3538
sprintf(value, "%s", git_config_bool(key_, value_)
3639
? "true" : "false");
3740
} else {
38-
value = strdup(value_ ? value_ : "");
41+
value = strdup(value_);
3942
}
4043
seen++;
4144
}

t/t1300-repo-config.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,13 @@ EOF
247247

248248
test_expect_success 'hierarchical section value' 'cmp .git/config expect'
249249

250+
cat > .git/config << EOF
251+
[novalue]
252+
variable
253+
EOF
254+
255+
test_expect_success 'get variable with no value' \
256+
'git-repo-config --get novalue.variable ^$'
257+
250258
test_done
251259

0 commit comments

Comments
 (0)