author | Junio C Hamano <gitster@pobox.com> | |
Wed, 27 Apr 2011 18:36:43 +0000 (11:36 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 27 Apr 2011 18:36:43 +0000 (11:36 -0700) |
* ef/maint-strbuf-init:
config: support values longer than 1023 bytes
strbuf: make sure buffer is zero-terminated
config: support values longer than 1023 bytes
strbuf: make sure buffer is zero-terminated
config.c | patch | blob | history | |
strbuf.c | patch | blob | history | |
t/t1303-wacky-config.sh | patch | blob | history |
diff --git a/config.c b/config.c
index d06fb19d511c29e92aa840c664618ca4a6f73fe6..5f9ec2894570d23f8b91327374a4d82dd46cbca3 100644 (file)
--- a/config.c
+++ b/config.c
static char *parse_value(void)
{
- static char value[1024];
- int quote = 0, comment = 0, len = 0, space = 0;
+ static struct strbuf value = STRBUF_INIT;
+ int quote = 0, comment = 0, space = 0;
+ strbuf_reset(&value);
for (;;) {
int c = get_next_char();
- if (len >= sizeof(value) - 1)
- return NULL;
if (c == '\n') {
if (quote)
return NULL;
- value[len] = 0;
- return value;
+ return value.buf;
}
if (comment)
continue;
if (isspace(c) && !quote) {
- if (len)
+ if (value.len)
space++;
continue;
}
}
}
for (; space; space--)
- value[len++] = ' ';
+ strbuf_addch(&value, ' ');
if (c == '\\') {
c = get_next_char();
switch (c) {
default:
return NULL;
}
- value[len++] = c;
+ strbuf_addch(&value, c);
continue;
}
if (c == '"') {
quote = 1-quote;
continue;
}
- value[len++] = c;
+ strbuf_addch(&value, c);
}
}
diff --git a/strbuf.c b/strbuf.c
index 77444a94df3d4a0cda6403957fd13ea262d3ab24..09c43ae59a7d4715c26f13d72ca37bc759d1c76d 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
{
sb->alloc = sb->len = 0;
sb->buf = strbuf_slopbuf;
- if (hint)
+ if (hint) {
strbuf_grow(sb, hint);
+ sb->buf[0] = '\0';
+ }
}
void strbuf_release(struct strbuf *sb)
index 080117c6bcbb61078539f36011ecd62780bae305..46103a1591680c9803588d24a135abf79fe64ae9 100755 (executable)
--- a/t/t1303-wacky-config.sh
+++ b/t/t1303-wacky-config.sh
test_expect_success 'do not crash on special long config line' '
setup &&
git config section.key "$LONG_VALUE" &&
- check section.key "fatal: bad config file line 2 in .git/config"
+ check section.key "$LONG_VALUE"
'
test_done