Thread (24 messages) flat view 24 messages, 6 authors, 2016-06-15
STALE3723d

[PATCH 04/10] config: avoid segfault when parsing command-line config

From: Jeff King <hidden>
Date: 2016-06-15 22:51:27
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 config.c               |    2 ++
 t/t1300-repo-config.sh |    4 ++++
 2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/config.c b/config.c
index ebd404a..2517b62 100644
--- a/config.c
+++ b/config.c
@@ -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]);
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 584e956..3e140c1 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -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
-- 
1.7.6.rc1.36.g91167
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help