Skip to content

Commit c5d6350

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c2c9be commit c5d6350

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

config.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static int git_config_parse_parameter(const char *text,
4646
struct strbuf **pair;
4747
strbuf_addstr(&tmp, text);
4848
pair = strbuf_split_max(&tmp, '=', 2);
49+
if (!pair[0])
50+
return error("bogus config parameter: %s", text);
4951
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
5052
strbuf_setlen(pair[0], pair[0]->len - 1);
5153
strbuf_trim(pair[0]);

t/t1300-repo-config.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,4 +918,8 @@ test_expect_success 'git -c complains about empty key' '
918918
test_must_fail git -c "=foo" rev-parse
919919
'
920920

921+
test_expect_success 'git -c complains about empty key and value' '
922+
test_must_fail git -c "" rev-parse
923+
'
924+
921925
test_done

0 commit comments

Comments
 (0)