{"thread":{"id":"26349","subject":"[PATCH] Disallow empty section and variable names","startedAt":"2011-01-27T14:52:53Z","lastAt":"2011-02-10T22:49:12Z","messageCount":9,"participants":["Libor Pechacek","Johannes Sixt","Jens Lehmann","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"159950","messageId":"20110127145253.GD6312@fm.suse.cz","threadId":"26349","inReplyTo":null,"subject":"[PATCH] Disallow empty section and variable names","fromName":"Libor Pechacek","fromEmail":"lpechacek@suse.cz","sentAt":"2011-01-27T14:52:53Z","receivedAt":"2011-01-27T14:52:53Z","isPatch":true,"sender":{"key":"lpechacek@suse.cz","avatar":null},"body":"It is possible to break you repository config by creating an invalid config\noption.  The config parser in turn chokes on it.\n\n$ git init\nInitialized empty Git repository in /tmp/gittest/.git/\n$ git config .foo false\n$ git config .foo\nfatal: bad config file line 6 in .git/config\n\nThis patch makes git-config reject keys which start or end with a dot.  The fix\nalso revealed a typo in t5526-fetch-submodules, which is fixed by this patch as\nwell.\n\nSigned-off-by: Libor Pechacek <lpechacek@suse.cz>\n---\n\nApplies on top \"Sanity-check config variable names\".\n\n config.c                    |    7 ++++++-\n t/t5526-fetch-submodules.sh |    2 +-\n 2 files changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex c976544..81a0705 100644\n--- a/config.c\n+++ b/config.c\n@@ -1119,7 +1119,7 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t * key name separated by a dot, we have to know where the dot is.\n \t */\n \n-\tif (last_dot == NULL) {\n+\tif (last_dot == NULL || *key == '.') {\n \t\terror(\"key does not contain a section: %s\", key);\n \t\treturn -2;\n \t}\n@@ -1156,6 +1156,11 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \tif (store_key)\n \t\t(*store_key)[i] = 0;\n \n+\tif (key[i-1] == '.') {\n+\t\terror(\"key does not contain variable name: %s\", key);\n+\t\tgoto out_free_ret_1;\n+\t}\n+\n \treturn 0;\n \n out_free_ret_1:\ndiff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh\nindex 884a5e5..7106c6c 100755\n--- a/t/t5526-fetch-submodules.sh\n+++ b/t/t5526-fetch-submodules.sh\n@@ -124,7 +124,7 @@ test_expect_success \"--recurse-submodules overrides fetchRecurseSubmodules setti\n \t(\n \t\tcd downstream &&\n \t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err &&\n-\t\tgit config -f --unset .gitmodules submodule.submodule.fetchRecurseSubmodules true &&\n+\t\tgit config -f .gitmodules --unset submodule.submodule.fetchRecurseSubmodules true &&\n \t\tgit config --unset submodule.submodule.fetchRecurseSubmodules\n \t) &&\n \ttest_cmp expect.out actual.out &&\n-- \n1.7.4.rc3.3.g8b2bfe\n"},{"id":"160065","messageId":"20110130203445.GA9689@fm.suse.cz","threadId":"26349","inReplyTo":"20110127145253.GD6312@fm.suse.cz","subject":"[PATCH v2] Disallow empty section and variable names","fromName":"Libor Pechacek","fromEmail":"lpechacek@suse.cz","sentAt":"2011-01-30T20:34:45Z","receivedAt":"2011-01-30T20:34:45Z","isPatch":true,"sender":{"key":"lpechacek@suse.cz","avatar":null},"body":"It is possible to break your repository config by creating an invalid key.  The\nconfig parser in turn chokes on it.\n\n$ git init\nInitialized empty Git repository in /tmp/gittest/.git/\n$ git config .foo false\n$ git config .foo\nfatal: bad config file line 6 in .git/config\n\nThis patch makes git-config reject keys which start or end with a dot, adds\ntests for these cases and also fixes a typo in t5526-fetch-submodules, which\nwas exposed by the new check.\n\nSigned-off-by: Libor Pechacek <lpechacek@suse.cz>\n---\n\nAdded tests for the cases checked, made git_config_parse_key consistently\nreturn -2 when the key is invalid.  Applies on top \"Sanity-check config\nvariable names\".\n\n config.c                    |    8 +++++++-\n t/t1300-repo-config.sh      |    4 ++++\n t/t5526-fetch-submodules.sh |    2 +-\n 3 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex fde91f5..e27a39f 100644\n--- a/config.c\n+++ b/config.c\n@@ -1120,11 +1120,17 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t * key name separated by a dot, we have to know where the dot is.\n \t */\n \n-\tif (last_dot == NULL) {\n+\tif (last_dot == NULL || *key == '.') {\n \t\terror(\"key does not contain a section: %s\", key);\n \t\treturn -2;\n \t}\n \n+\ti = strlen(key);\n+\tif (i && key[i-1] == '.') {\n+\t\terror(\"key does not contain variable name: %s\", key);\n+\t\treturn -2;\n+\t}\n+\n \tbaselen = last_dot - key;\n \tif (baselen_)\n \t\t*baselen_ = baselen;\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex c3d91d1..568d51d 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -889,6 +889,10 @@ test_expect_success 'key sanity-checking' '\n \ttest_must_fail git config foo.1bar &&\n \ttest_must_fail git config foo.\"ba\n \t\t\t\tz\".bar &&\n+\ttest_must_fail git config . &&\n+\ttest_must_fail git config .foo &&\n+\ttest_must_fail git config foo. &&\n+\ttest_must_fail git config .foo. &&\n \tgit config foo.bar true &&\n \tgit config foo.\"ba =z\".bar false\n '\ndiff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh\nindex 884a5e5..7106c6c 100755\n--- a/t/t5526-fetch-submodules.sh\n+++ b/t/t5526-fetch-submodules.sh\n@@ -124,7 +124,7 @@ test_expect_success \"--recurse-submodules overrides fetchRecurseSubmodules setti\n \t(\n \t\tcd downstream &&\n \t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err &&\n-\t\tgit config -f --unset .gitmodules submodule.submodule.fetchRecurseSubmodules true &&\n+\t\tgit config -f .gitmodules --unset submodule.submodule.fetchRecurseSubmodules true &&\n \t\tgit config --unset submodule.submodule.fetchRecurseSubmodules\n \t) &&\n \ttest_cmp expect.out actual.out &&\n-- \n1.7.4.rc3.11.g54760\n"},{"id":"160086","messageId":"4D46694F.5070208@viscovery.net","threadId":"26349","inReplyTo":"20110130203445.GA9689@fm.suse.cz","subject":"Re: [PATCH v2] Disallow empty section and variable names","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-01-31T07:48:31Z","receivedAt":"2011-01-31T07:48:31Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 1/30/2011 21:34, schrieb Libor Pechacek:\n> It is possible to break your repository config by creating an invalid key.  The\n> config parser in turn chokes on it.\n> \n> $ git init\n> Initialized empty Git repository in /tmp/gittest/.git/\n> $ git config .foo false\n> $ git config .foo\n> fatal: bad config file line 6 in .git/config\n\nJust a nit: Your example is misleading because it \"only\" shows that if you\nshove in junk, and ask for junk, you get breakage. However, the breakage\nis much more serious, and you could have demonstrated it, if you had\nwritten your example like this:\n\n$ git config .foo false\n$ git config user.email\nfatal: bad config file line 6 in .git/config\n\n> +\ttest_must_fail git config . &&\n> +\ttest_must_fail git config .foo &&\n> +\ttest_must_fail git config foo. &&\n> +\ttest_must_fail git config .foo. &&\n\nNot a nit: These tests only show that 'git config' cannot be asked for\njunk, but they do not show that you cannot insert junk into the config\nfile anymore using 'git config'.\n\n-- Hannes\n"},{"id":"160088","messageId":"20110131091728.GB24297@fm.suse.cz","threadId":"26349","inReplyTo":"4D46694F.5070208@viscovery.net","subject":"Re: [PATCH v2] Disallow empty section and variable names","fromName":"Libor Pechacek","fromEmail":"lpechacek@suse.cz","sentAt":"2011-01-31T09:17:28Z","receivedAt":"2011-01-31T09:17:28Z","isPatch":true,"sender":{"key":"lpechacek@suse.cz","avatar":null},"body":"On Mon 31-01-11 08:48:31, Johannes Sixt wrote:\n> Am 1/30/2011 21:34, schrieb Libor Pechacek:\n> > It is possible to break your repository config by creating an invalid key.  The\n> > config parser in turn chokes on it.\n> > \n> > $ git init\n> > Initialized empty Git repository in /tmp/gittest/.git/\n> > $ git config .foo false\n> > $ git config .foo\n> > fatal: bad config file line 6 in .git/config\n> \n> Just a nit: Your example is misleading because it \"only\" shows that if you\n> shove in junk, and ask for junk, you get breakage. However, the breakage\n> is much more serious, and you could have demonstrated it, if you had\n> written your example like this:\n> \n> $ git config .foo false\n> $ git config user.email\n> fatal: bad config file line 6 in .git/config\n\nYes, that one is more persuasive.  Thanks for hint.\n\n> > +\ttest_must_fail git config . &&\n> > +\ttest_must_fail git config .foo &&\n> > +\ttest_must_fail git config foo. &&\n> > +\ttest_must_fail git config .foo. &&\n> \n> Not a nit: These tests only show that 'git config' cannot be asked for\n> junk, but they do not show that you cannot insert junk into the config\n> file anymore using 'git config'.\n\nThis change builds on top of \"Sanity-check config variable names\" which makes\nsetting and getting values use the same key checking routine.  For the moment,\nit does not matter if we test the \"set\" ot \"get\" path.\n\nYet, I accept the get/set operations can use different key checking routine in\nthe future (although I can't imagine the reson for it), and overall testing\nthe \"set\" path is in line with the idea of the patch.\n\nThanks for input, I'll send updated patch.\n\nLibor\n-- \nLibor Pechacek\nSUSE L3 Team, Prague\n"},{"id":"160089","messageId":"4D468109.8020409@viscovery.net","threadId":"26349","inReplyTo":"20110131091728.GB24297@fm.suse.cz","subject":"Re: [PATCH v2] Disallow empty section and variable names","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2011-01-31T09:29:45Z","receivedAt":"2011-01-31T09:29:45Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 1/31/2011 10:17, schrieb Libor Pechacek:\n> On Mon 31-01-11 08:48:31, Johannes Sixt wrote:\n>> Am 1/30/2011 21:34, schrieb Libor Pechacek:\n>>> +\ttest_must_fail git config . &&\n>>> +\ttest_must_fail git config .foo &&\n>>> +\ttest_must_fail git config foo. &&\n>>> +\ttest_must_fail git config .foo. &&\n>>\n>> Not a nit: These tests only show that 'git config' cannot be asked for\n>> junk, but they do not show that you cannot insert junk into the config\n>> file anymore using 'git config'.\n> \n> This change builds on top of \"Sanity-check config variable names\" which makes\n> setting and getting values use the same key checking routine.  For the moment,\n> it does not matter if we test the \"set\" ot \"get\" path.\n\nThe purpose of tests is not to check the implementation, but the\nobservable behavior. Therefore, you want to write a test case to make sure\nthat neither usage is broken by future changes.\n\n-- Hannes\n"},{"id":"160092","messageId":"20110131130855.GC24297@fm.suse.cz","threadId":"26349","inReplyTo":"4D468109.8020409@viscovery.net","subject":"[PATCH v3] Disallow empty section and variable names","fromName":"Libor Pechacek","fromEmail":"lpechacek@suse.cz","sentAt":"2011-01-31T13:08:56Z","receivedAt":"2011-01-31T13:08:56Z","isPatch":true,"sender":{"key":"lpechacek@suse.cz","avatar":null},"body":"It is possible to break your repository config by creating an invalid key.  The\nconfig parser in turn chokes on it.\n\n$ git init\nInitialized empty Git repository in /tmp/gittest/.git/\n$ git config .foo false\n$ git config core.bare\nfatal: bad config file line 6 in .git/config\n\nThis patch makes git-config reject keys which start or end with a dot, adds\ntests for these cases and also fixes a typo in t5526-fetch-submodules, which\nwas exposed by the new check.\n\nSigned-off-by: Libor Pechacek <lpechacek@suse.cz>\nCc: Johannes Sixt <j.sixt@viscovery.net>\n---\n\nIncoporated feedback from Johannes, introduced keylen local variable to improve\nreadability of the code.  Applies on top \"Sanity-check config variable names\".\n\n config.c                    |   10 ++++++++--\n t/t1300-repo-config.sh      |    4 ++++\n t/t5526-fetch-submodules.sh |    2 +-\n 3 files changed, 13 insertions(+), 3 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex fde91f5..5eb89a7 100644\n--- a/config.c\n+++ b/config.c\n@@ -1113,6 +1113,7 @@ int git_config_set(const char *key, const char *value)\n int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n {\n \tint i, dot, baselen;\n+\tint keylen = strlen(key);\n \tconst char *last_dot = strrchr(key, '.');\n \n \t/*\n@@ -1120,11 +1121,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t * key name separated by a dot, we have to know where the dot is.\n \t */\n \n-\tif (last_dot == NULL) {\n+\tif (last_dot == NULL || *key == '.') {\n \t\terror(\"key does not contain a section: %s\", key);\n \t\treturn -2;\n \t}\n \n+\tif (keylen && key[keylen-1] == '.') {\n+\t\terror(\"key does not contain variable name: %s\", key);\n+\t\treturn -2;\n+\t}\n+\n \tbaselen = last_dot - key;\n \tif (baselen_)\n \t\t*baselen_ = baselen;\n@@ -1132,7 +1138,7 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t/*\n \t * Validate the key and while at it, lower case it for matching.\n \t */\n-\t*store_key = xmalloc(strlen(key) + 1);\n+\t*store_key = xmalloc(keylen + 1);\n \n \tdot = 0;\n \tfor (i = 0; key[i]; i++) {\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex c3d91d1..53fb822 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -889,6 +889,10 @@ test_expect_success 'key sanity-checking' '\n \ttest_must_fail git config foo.1bar &&\n \ttest_must_fail git config foo.\"ba\n \t\t\t\tz\".bar &&\n+\ttest_must_fail git config . false &&\n+\ttest_must_fail git config .foo false &&\n+\ttest_must_fail git config foo. false &&\n+\ttest_must_fail git config .foo. false &&\n \tgit config foo.bar true &&\n \tgit config foo.\"ba =z\".bar false\n '\ndiff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh\nindex 884a5e5..7106c6c 100755\n--- a/t/t5526-fetch-submodules.sh\n+++ b/t/t5526-fetch-submodules.sh\n@@ -124,7 +124,7 @@ test_expect_success \"--recurse-submodules overrides fetchRecurseSubmodules setti\n \t(\n \t\tcd downstream &&\n \t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err &&\n-\t\tgit config -f --unset .gitmodules submodule.submodule.fetchRecurseSubmodules true &&\n+\t\tgit config -f .gitmodules --unset submodule.submodule.fetchRecurseSubmodules true &&\n \t\tgit config --unset submodule.submodule.fetchRecurseSubmodules\n \t) &&\n \ttest_cmp expect.out actual.out &&\n-- \n1.7.4.rc3.11.g863f7\n"},{"id":"160096","messageId":"4D46E7E7.4010805@web.de","threadId":"26349","inReplyTo":"20110131130855.GC24297@fm.suse.cz","subject":"Re: [PATCH v3] Disallow empty section and variable names","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2011-01-31T16:48:39Z","receivedAt":"2011-01-31T16:48:39Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 31.01.2011 14:08, schrieb Libor Pechacek:\n> diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh\n> index 884a5e5..7106c6c 100755\n> --- a/t/t5526-fetch-submodules.sh\n> +++ b/t/t5526-fetch-submodules.sh\n> @@ -124,7 +124,7 @@ test_expect_success \"--recurse-submodules overrides fetchRecurseSubmodules setti\n>  \t(\n>  \t\tcd downstream &&\n>  \t\tgit fetch --recurse-submodules >../actual.out 2>../actual.err &&\n> -\t\tgit config -f --unset .gitmodules submodule.submodule.fetchRecurseSubmodules true &&\n> +\t\tgit config -f .gitmodules --unset submodule.submodule.fetchRecurseSubmodules true &&\n\nThis is not quite the right fix (notice the extra \"true\" value\nat the end). IMHO this should be fixed separately, patch coming.\n"},{"id":"160159","messageId":"20110201071347.GH24297@fm.suse.cz","threadId":"26349","inReplyTo":"4D46E7E7.4010805@web.de","subject":"[PATCH v4] Disallow empty section and variable names","fromName":"Libor Pechacek","fromEmail":"lpechacek@suse.cz","sentAt":"2011-02-01T07:13:47Z","receivedAt":"2011-02-01T07:13:47Z","isPatch":true,"sender":{"key":"lpechacek@suse.cz","avatar":null},"body":"It is possible to break your repository config by creating an invalid key.  The\nconfig parser in turn chokes on it.\n\n$ git init\nInitialized empty Git repository in /tmp/gittest/.git/\n$ git config .foo false\n$ git config core.bare\nfatal: bad config file line 6 in .git/config\n\nThis patch makes git-config reject keys which start or end with a dot and adds\ntests for these cases.\n\nSigned-off-by: Libor Pechacek <lpechacek@suse.cz>\n---\n\nFix in t5526-fetch-submodules.sh was posted separately by Jens Lehmann.\nApplies on top \"Sanity-check config variable names\".\n\n config.c               |   10 ++++++++--\n t/t1300-repo-config.sh |    4 ++++\n 2 files changed, 12 insertions(+), 2 deletions(-)\n\ndiff --git a/config.c b/config.c\nindex fde91f5..5eb89a7 100644\n--- a/config.c\n+++ b/config.c\n@@ -1113,6 +1113,7 @@ int git_config_set(const char *key, const char *value)\n int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n {\n \tint i, dot, baselen;\n+\tint keylen = strlen(key);\n \tconst char *last_dot = strrchr(key, '.');\n \n \t/*\n@@ -1120,11 +1121,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t * key name separated by a dot, we have to know where the dot is.\n \t */\n \n-\tif (last_dot == NULL) {\n+\tif (last_dot == NULL || *key == '.') {\n \t\terror(\"key does not contain a section: %s\", key);\n \t\treturn -2;\n \t}\n \n+\tif (keylen && key[keylen-1] == '.') {\n+\t\terror(\"key does not contain variable name: %s\", key);\n+\t\treturn -2;\n+\t}\n+\n \tbaselen = last_dot - key;\n \tif (baselen_)\n \t\t*baselen_ = baselen;\n@@ -1132,7 +1138,7 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t/*\n \t * Validate the key and while at it, lower case it for matching.\n \t */\n-\t*store_key = xmalloc(strlen(key) + 1);\n+\t*store_key = xmalloc(keylen + 1);\n \n \tdot = 0;\n \tfor (i = 0; key[i]; i++) {\ndiff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh\nindex c3d91d1..53fb822 100755\n--- a/t/t1300-repo-config.sh\n+++ b/t/t1300-repo-config.sh\n@@ -889,6 +889,10 @@ test_expect_success 'key sanity-checking' '\n \ttest_must_fail git config foo.1bar &&\n \ttest_must_fail git config foo.\"ba\n \t\t\t\tz\".bar &&\n+\ttest_must_fail git config . false &&\n+\ttest_must_fail git config .foo false &&\n+\ttest_must_fail git config foo. false &&\n+\ttest_must_fail git config .foo. false &&\n \tgit config foo.bar true &&\n \tgit config foo.\"ba =z\".bar false\n '\n-- \n1.7.4.rc3.11.g863f7\n"},{"id":"160848","messageId":"7v1v3f33pz.fsf@alter.siamese.dyndns.org","threadId":"26349","inReplyTo":"20110201071347.GH24297@fm.suse.cz","subject":"Re: [PATCH v4] Disallow empty section and variable names","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-02-10T22:49:12Z","receivedAt":"2011-02-10T22:49:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Libor Pechacek <lpechacek@suse.cz> writes:\n\n> diff --git a/config.c b/config.c\n> index fde91f5..5eb89a7 100644\n> --- a/config.c\n> +++ b/config.c\n> @@ -1113,6 +1113,7 @@ int git_config_set(const char *key, const char *value)\n>  int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n>  {\n>  \tint i, dot, baselen;\n> +\tint keylen = strlen(key);\n>  \tconst char *last_dot = strrchr(key, '.');\n>  \n>  \t/*\n> @@ -1120,11 +1121,16 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n>  \t * key name separated by a dot, we have to know where the dot is.\n>  \t */\n>  \n> -\tif (last_dot == NULL) {\n> +\tif (last_dot == NULL || *key == '.') {\n>  \t\terror(\"key does not contain a section: %s\", key);\n>  \t\treturn -2;\n>  \t}\n>  \n> +\tif (keylen && key[keylen-1] == '.') {\n\nAren't these the same as saying\n\n\tif (!last_dot || last_dot == key) {\n\t\t...\n        }\n\tif (!last_dot[1]) { /* we know last_dot is not NULL */\n        \t...\n\t}\n\nAgain, a minimum fix-up on top of your patch.\nThanks.\n\n\ndiff --git a/config.c b/config.c\nindex 75dd629..d5bb862 100644\n--- a/config.c\n+++ b/config.c\n@@ -1113,7 +1113,6 @@ int git_config_set(const char *key, const char *value)\n int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n {\n \tint i, dot, baselen;\n-\tint keylen = strlen(key);\n \tconst char *last_dot = strrchr(key, '.');\n \n \t/*\n@@ -1121,12 +1120,12 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t * key name separated by a dot, we have to know where the dot is.\n \t */\n \n-\tif (last_dot == NULL || *key == '.') {\n+\tif (last_dot == NULL || last_dot == key) {\n \t\terror(\"key does not contain a section: %s\", key);\n \t\treturn -2;\n \t}\n \n-\tif (keylen && key[keylen-1] == '.') {\n+\tif (!last_dot[1]) {\n \t\terror(\"key does not contain variable name: %s\", key);\n \t\treturn -2;\n \t}\n@@ -1138,7 +1137,7 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_)\n \t/*\n \t * Validate the key and while at it, lower case it for matching.\n \t */\n-\t*store_key = xmalloc(keylen + 1);\n+\t*store_key = xmalloc(strlen(key) + 1);\n \n \tdot = 0;\n \tfor (i = 0; key[i]; i++) {\n"}]}