Merge branch 'ef/maint-strbuf-init'
* ef/maint-strbuf-init: config: support values longer than 1023 bytes strbuf: make sure buffer is zero-terminated
This commit is contained in:
18
config.c
18
config.c
@@ -133,23 +133,21 @@ static int get_next_char(void)
|
|||||||
|
|
||||||
static char *parse_value(void)
|
static char *parse_value(void)
|
||||||
{
|
{
|
||||||
static char value[1024];
|
static struct strbuf value = STRBUF_INIT;
|
||||||
int quote = 0, comment = 0, len = 0, space = 0;
|
int quote = 0, comment = 0, space = 0;
|
||||||
|
|
||||||
|
strbuf_reset(&value);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c = get_next_char();
|
int c = get_next_char();
|
||||||
if (len >= sizeof(value) - 1)
|
|
||||||
return NULL;
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
if (quote)
|
if (quote)
|
||||||
return NULL;
|
return NULL;
|
||||||
value[len] = 0;
|
return value.buf;
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
if (comment)
|
if (comment)
|
||||||
continue;
|
continue;
|
||||||
if (isspace(c) && !quote) {
|
if (isspace(c) && !quote) {
|
||||||
if (len)
|
if (value.len)
|
||||||
space++;
|
space++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -160,7 +158,7 @@ static char *parse_value(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (; space; space--)
|
for (; space; space--)
|
||||||
value[len++] = ' ';
|
strbuf_addch(&value, ' ');
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = get_next_char();
|
c = get_next_char();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
@@ -182,14 +180,14 @@ static char *parse_value(void)
|
|||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
value[len++] = c;
|
strbuf_addch(&value, c);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
quote = 1-quote;
|
quote = 1-quote;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
value[len++] = c;
|
strbuf_addch(&value, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
strbuf.c
4
strbuf.c
@@ -30,8 +30,10 @@ void strbuf_init(struct strbuf *sb, size_t hint)
|
|||||||
{
|
{
|
||||||
sb->alloc = sb->len = 0;
|
sb->alloc = sb->len = 0;
|
||||||
sb->buf = strbuf_slopbuf;
|
sb->buf = strbuf_slopbuf;
|
||||||
if (hint)
|
if (hint) {
|
||||||
strbuf_grow(sb, hint);
|
strbuf_grow(sb, hint);
|
||||||
|
sb->buf[0] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void strbuf_release(struct strbuf *sb)
|
void strbuf_release(struct strbuf *sb)
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ LONG_VALUE=$(printf "x%01021dx a" 7)
|
|||||||
test_expect_success 'do not crash on special long config line' '
|
test_expect_success 'do not crash on special long config line' '
|
||||||
setup &&
|
setup &&
|
||||||
git config section.key "$LONG_VALUE" &&
|
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
|
test_done
|
||||||
|
|||||||
Reference in New Issue
Block a user