Skip to content

Commit

Permalink
config: avoid segfault when parsing command-line config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Jun 22, 2011
1 parent 1c2c9be commit c5d6350
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions config.c
Expand Up @@ -46,6 +46,8 @@ static int git_config_parse_parameter(const char *text,
struct strbuf **pair;
strbuf_addstr(&tmp, text);
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] == '=')
strbuf_setlen(pair[0], pair[0]->len - 1);
strbuf_trim(pair[0]);
Expand Down
4 changes: 4 additions & 0 deletions t/t1300-repo-config.sh
Expand Up @@ -918,4 +918,8 @@ test_expect_success 'git -c complains about empty key' '
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

0 comments on commit c5d6350

Please sign in to comment.