Skip to content

Commit 2169ddc

Browse files
Libor Pechacekgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b09c53a commit 2169ddc

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

config.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,11 +1120,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)
11201120
* key name separated by a dot, we have to know where the dot is.
11211121
*/
11221122

1123-
if (last_dot == NULL) {
1123+
if (last_dot == NULL || last_dot == key) {
11241124
error("key does not contain a section: %s", key);
11251125
return -2;
11261126
}
11271127

1128+
if (!last_dot[1]) {
1129+
error("key does not contain variable name: %s", key);
1130+
return -2;
1131+
}
1132+
11281133
baselen = last_dot - key;
11291134
if (baselen_)
11301135
*baselen_ = baselen;

t/t1300-repo-config.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,10 @@ test_expect_success 'key sanity-checking' '
889889
test_must_fail git config foo.1bar &&
890890
test_must_fail git config foo."ba
891891
z".bar &&
892+
test_must_fail git config . false &&
893+
test_must_fail git config .foo false &&
894+
test_must_fail git config foo. false &&
895+
test_must_fail git config .foo. false &&
892896
git config foo.bar true &&
893897
git config foo."ba =z".bar false
894898
'

0 commit comments

Comments
 (0)