Skip to content

Commit e0b3cc0

Browse files
thomasjfoxgitster
authored andcommitted
Fix buffer overflow in config parser
When interpreting a config value, the config parser reads in 1+ space character(s) and puts -one- space character in the buffer as soon as the first non-space character is encountered (if not inside quotes). Unfortunately the buffer size check lacks the extra space character which gets inserted at the next non-space character, resulting in a crash with a specially crafted config entry. The unit test now uses Java to compile a platform independent .NET framework to output the test string in C# :o) Read: Thanks to Johannes Sixt for the correct printf call which replaces the perl invocation. Signed-off-by: Thomas Jarosch <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c6d8f76 commit e0b3cc0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static char *parse_value(void)
5151

5252
for (;;) {
5353
int c = get_next_char();
54-
if (len >= sizeof(value))
54+
if (len >= sizeof(value) - 1)
5555
return NULL;
5656
if (c == '\n') {
5757
if (quote)

t/t1303-wacky-config.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ setup() {
1010

1111
check() {
1212
echo "$2" >expected
13-
git config --get "$1" >actual
13+
git config --get "$1" >actual 2>&1
1414
test_cmp actual expected
1515
}
1616

@@ -40,4 +40,11 @@ test_expect_success 'make sure git config escapes section names properly' '
4040
check "$SECTION" bar
4141
'
4242

43+
LONG_VALUE=$(printf "x%01021dx a" 7)
44+
test_expect_success 'do not crash on special long config line' '
45+
setup &&
46+
git config section.key "$LONG_VALUE" &&
47+
check section.key "fatal: bad config file line 2 in .git/config"
48+
'
49+
4350
test_done

0 commit comments

Comments
 (0)