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>
Jeff King committed
Jun 9, 2011 at 11:52 UTC
c5d6350bdc8d0d8bd4bd1aa0273313e71cd548f6
2 files changed
+6
config.c
+2
@@ -46,6 +46,8 @@ static int git_config_parse_parameter(const char *text,
46
struct strbuf **pair;
47
strbuf_addstr(&tmp, text);
48
pair = strbuf_split_max(&tmp, '=', 2);
49
+ if (!pair[0])
50
+ return error("bogus config parameter: %s", text);
51
if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=')
52
strbuf_setlen(pair[0], pair[0]->len - 1);
53
strbuf_trim(pair[0]);
t/t1300-repo-config.sh
+4
@@ -918,4 +918,8 @@ test_expect_success 'git -c complains about empty key' '
918
test_must_fail git -c "=foo" rev-parse
919
'
920
921
+test_expect_success 'git -c complains about empty key and value' '
922
+ test_must_fail git -c "" rev-parse
923
+'
924
+
925
test_done