[PATCH] Fix for config file section parsing.
From: sean <hidden>
Date: 2016-06-15 22:42:25
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: sean <hidden>
Date: 2016-06-15 22:42:25
Subsystem:
the rest · Maintainer:
Linus Torvalds
Currently, if the target key has a section that matches
the initial substring of another section we mistakenly
believe we've found the correct section. To avoid this
problem, ensure that the section lengths are identical
before comparison.
Signed-off-by: Sean Estabrooks <redacted>
---
Here's an example of the problem:
$ git repo-config a.b.c d
$ cat .git/config
[a.b]
c = d
$ git repo-config a.x y
$ cat .git/config
[a.b]
c = d
x = y
config.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
f956fd1a6b1d3c82d9bc735427b58ec41d9e5dd1diff --git a/config.c b/config.c
index 4e1f0c2..a3e14d7 100644
--- a/config.c
+++ b/config.c@@ -335,8 +335,9 @@ static int store_aux(const char* key, co store.offset[store.seen] = ftell(config_file); store.state = KEY_SEEN; store.seen++; - } else if(!strncmp(key, store.key, store.baselen)) - store.state = SECTION_SEEN; + } else if (strrchr(key, '.') - key == store.baselen && + !strncmp(key, store.key, store.baselen)) + store.state = SECTION_SEEN; } return 0; }
--
1.3.2.g2fb9