@matheusbsbs / matheus-bagliano / commits / e0b3cc0dff
Fork 0

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 <thomas.jarosch@intra2net.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Jarosch committed Apr 17, 2009 at 14:05 UTC e0b3cc0dffbc965ffa33155cbdcf8d44716c134c
2 files changed +9 -2
config.c
+1 -1
@@ -51,7 +51,7 @@ static char *parse_value(void)
51
52 for (;;) {
53 int c = get_next_char();
54 - if (len >= sizeof(value))
54 + if (len >= sizeof(value) - 1)
55 return NULL;
56 if (c == '\n') {
57 if (quote)
t/t1303-wacky-config.sh
+8 -1
@@ -10,7 +10,7 @@ setup() {
10
11 check() {
12 echo "$2" >expected
13 - git config --get "$1" >actual
13 + git config --get "$1" >actual 2>&1
14 test_cmp actual expected
15 }
16
@@ -40,4 +40,11 @@ test_expect_success 'make sure git config escapes section names properly' '
40 check "$SECTION" bar
41 '
42
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 +
50 test_done