mirror of
https://github.com/git/git
synced 2024-10-02 14:45:21 +00:00
config: avoid segfault when parsing command-line config
We already check for an empty key on the left side of an equals, but we would segfault if there was no content at all. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1c2c9bee1b
commit
c5d6350bdc
2
config.c
2
config.c
|
@ -46,6 +46,8 @@ static int git_config_parse_parameter(const char *text,
|
||||||
struct strbuf **pair;
|
struct strbuf **pair;
|
||||||
strbuf_addstr(&tmp, text);
|
strbuf_addstr(&tmp, text);
|
||||||
pair = strbuf_split_max(&tmp, '=', 2);
|
pair = strbuf_split_max(&tmp, '=', 2);
|
||||||
|
if (!pair[0])
|
||||||
|
return error("bogus config parameter: %s", text);
|
||||||
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
|
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
|
||||||
strbuf_setlen(pair[0], pair[0]->len - 1);
|
strbuf_setlen(pair[0], pair[0]->len - 1);
|
||||||
strbuf_trim(pair[0]);
|
strbuf_trim(pair[0]);
|
||||||
|
|
|
@ -918,4 +918,8 @@ test_expect_success 'git -c complains about empty key' '
|
||||||
test_must_fail git -c "=foo" rev-parse
|
test_must_fail git -c "=foo" rev-parse
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git -c complains about empty key and value' '
|
||||||
|
test_must_fail git -c "" rev-parse
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue