path: root/builtin/config.c
diff options
authorTanay Abhra <>2014-08-18 10:17:57 (GMT)
committerJunio C Hamano <>2014-08-18 17:45:59 (GMT)
commitc8466645edd1413c7efed824f5bddac457eb77f9 (patch)
tree1e0aa1584d4b7155e56f62bead24136ef54f8cde /builtin/config.c
parent32f56600bb6ac6fc57183e79d2c1515dfa56672f (diff)
make config --add behave correctly for empty and NULL values
Currently if we have a config file like, [foo] baz bar = and we try something like, "git config --add foo.baz roll", Git will segfault. Moreover, for "git config --add roll", it will overwrite the original value instead of appending after the existing empty value. The problem lies with the regexp used for simulating --add in `git_config_set_multivar_in_file()`, "^$", which in ideal case should not match with any string but is true for empty strings. Instead use a regexp like "a^" which can not be true for any string, empty or not. For removing the segfault add a check for NULL values in `matches()` in config.c. Signed-off-by: Tanay Abhra <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/config.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 5677c94..8224699 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -599,7 +599,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
check_argc(argc, 2, 2);
value = normalize_value(argv[0], argv[1]);
return git_config_set_multivar_in_file(given_config_source.file,
- argv[0], value, "^$", 0);
+ argv[0], value, "a^", 0);
else if (actions == ACTION_REPLACE_ALL) {