From 5bf6529aaa3fa829328ae00ddf7aa851935443b5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:51:36 -0400 Subject: fix "git -c" parsing of values with equals signs If you do something like: git -c core.foo="value with = in it" ... we would split your option on "=" into three fields and throw away the third one. With this patch we correctly take everything after the first "=" as the value (keys cannot have an equals sign in them, so the parsing is unambiguous). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 61de4d6a17..84ff346859 100644 --- a/config.c +++ b/config.c @@ -45,7 +45,7 @@ static int git_config_parse_parameter(const char *text, struct strbuf tmp = STRBUF_INIT; struct strbuf **pair; strbuf_addstr(&tmp, text); - pair = strbuf_split(&tmp, '='); + pair = strbuf_split_max(&tmp, '=', 2); if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') strbuf_setlen(pair[0], pair[0]->len - 1); strbuf_trim(pair[0]); -- cgit v1.2.3 From 1c2c9bee1bad9a4133a934d04c32b033cc16c8aa Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:52:32 -0400 Subject: config: die on error in command-line config The error handling for git_config is somewhat confusing. We collect errors from running git_config_from_file on the various config files and carefully pass them back up. But the two odd things are: 1. We actually die on most errors in git_config_from_file. In fact, the only error we actually pass back up is if fopen() fails on the file. 2. Most callers of git_config do not check the error return at all, but will continue if git_config reports an error. When the code for "git -c core.foo=bar" was added, it dutifully passed errors up the call stack, only for them to be eventually ignored. This makes it inconsistent with the file-parsing code, which will die when it sees malformed config. And it's somewhat unsafe, because it means an error in parsing a typo like: git -c clean.requireforce=ture clean will continue the command, ignoring the config the user tried to give. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config.c') diff --git a/config.c b/config.c index 84ff346859..2567b546a3 100644 --- a/config.c +++ b/config.c @@ -858,7 +858,7 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config) switch (git_config_from_parameters(fn, data)) { case -1: /* error */ - ret--; + die("unable to parse command-line config"); break; case 0: /* found nothing */ break; -- cgit v1.2.3 From c5d6350bdc8d0d8bd4bd1aa0273313e71cd548f6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:52:43 -0400 Subject: 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 Signed-off-by: Junio C Hamano --- config.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'config.c') diff --git a/config.c b/config.c index 2567b546a3..9939f65d9e 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]); -- cgit v1.2.3 From f77bccaeba7a4c542e9b89d144af74bddd36fd08 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:55:09 -0400 Subject: config: use strbuf_split_str instead of a temporary strbuf This saves an allocation and copy, and also fixes a minor memory leak. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- config.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 9939f65d9e..44b2c93b24 100644 --- a/config.c +++ b/config.c @@ -42,10 +42,8 @@ void git_config_push_parameter(const char *text) static int git_config_parse_parameter(const char *text, config_fn_t fn, void *data) { - struct strbuf tmp = STRBUF_INIT; struct strbuf **pair; - strbuf_addstr(&tmp, text); - pair = strbuf_split_max(&tmp, '=', 2); + pair = strbuf_split_str(text, '=', 2); if (!pair[0]) return error("bogus config parameter: %s", text); if (pair[0]->len && pair[0]->buf[pair[0]->len - 1] == '=') -- cgit v1.2.3