path: root/config.c
diff options
authorLibor Pechacek <>2011-02-01 07:13:47 (GMT)
committerJunio C Hamano <>2011-02-22 23:19:46 (GMT)
commit2169ddc056b56deba701cbbba28cdaf2e9821224 (patch)
tree63efb8d26f51e9c09752151e398dfb122eeb2053 /config.c
parentb09c53a3e331211fc0154de8ebb271e48f8c7ee5 (diff)
Disallow empty section and variable names
It is possible to break your repository config by creating an invalid key. The config parser in turn chokes on it: $ git init Initialized empty Git repository in /tmp/gittest/.git/ $ git config .foo false $ git config core.bare fatal: bad config file line 6 in .git/config This patch makes git-config reject keys which start or end with a dot and adds tests for these cases. Signed-off-by: Libor Pechacek <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'config.c')
1 files changed, 6 insertions, 1 deletions
diff --git a/config.c b/config.c
index f758734..d5bb862 100644
--- a/config.c
+++ b/config.c
@@ -1120,11 +1120,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)
* key name separated by a dot, we have to know where the dot is.
- if (last_dot == NULL) {
+ if (last_dot == NULL || last_dot == key) {
error("key does not contain a section: %s", key);
return -2;
+ if (!last_dot[1]) {
+ error("key does not contain variable name: %s", key);
+ return -2;
+ }
baselen = last_dot - key;
if (baselen_)
*baselen_ = baselen;