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

config: support values longer than 1023 bytes

parse_value in config.c has a static buffer of 1024 bytes that it parse the value into. This can sometimes be a problem when a config file contains very long values. It's particularly amusing that git-config already is able to write such files, so it should probably be able to read them as well. Fix this by using a strbuf instead of a fixed-size buffer. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Apr 10, 2011 at 22:54 UTC e96c19c50fb0807570b85cb5b8aae6dfcfa9b9ec
2 files changed +9 -11
config.c
+8 -10
@@ -46,23 +46,21 @@ static int get_next_char(void)
46
47 static char *parse_value(void)
48 {
49 - static char value[1024];
50 - int quote = 0, comment = 0, len = 0, space = 0;
49 + static struct strbuf value = STRBUF_INIT;
50 + int quote = 0, comment = 0, space = 0;
51
52 + strbuf_reset(&value);
53 for (;;) {
54 int c = get_next_char();
54 - if (len >= sizeof(value) - 1)
55 - return NULL;
55 if (c == '\n') {
56 if (quote)
57 return NULL;
59 - value[len] = 0;
60 - return value;
58 + return value.buf;
59 }
60 if (comment)
61 continue;
62 if (isspace(c) && !quote) {
65 - if (len)
63 + if (value.len)
64 space++;
65 continue;
66 }
@@ -73,7 +71,7 @@ static char *parse_value(void)
71 }
72 }
73 for (; space; space--)
76 - value[len++] = ' ';
74 + strbuf_addch(&value, ' ');
75 if (c == '\\') {
76 c = get_next_char();
77 switch (c) {
@@ -95,14 +93,14 @@ static char *parse_value(void)
93 default:
94 return NULL;
95 }
98 - value[len++] = c;
96 + strbuf_addch(&value, c);
97 continue;
98 }
99 if (c == '"') {
100 quote = 1-quote;
101 continue;
102 }
105 - value[len++] = c;
103 + strbuf_addch(&value, c);
104 }
105 }
106
t/t1303-wacky-config.sh
+1 -1
@@ -44,7 +44,7 @@ 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"
47 + check section.key "$LONG_VALUE"
48 '
49
50 test_done