about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLukas Fleischer2013-06-28 08:58:14 +0000
committerJason A. Donenfeld2013-08-12 13:14:11 -0600
commit86e309fcb5ba64d29821b1e40407a4007e34df75 (patch)
tree16a7a9bee74cefb9916dbe229f492dc23cf28f3d
parentMakefile: Change default prefix to "/usr/local" (diff)
downloadcgit-86e309fcb5ba64d29821b1e40407a4007e34df75.tar.gz
cgit-86e309fcb5ba64d29821b1e40407a4007e34df75.zip
Fix section-from-path > 1
When having found the first path separator occurrence at position i, we
invoked strchr() on the same position i in subsequent iterations
resulting in the same path separator being returned by strchr() over and
over again. Increase the position by one to skip the occurrence that has
just been found and advance to the next separator.

Reported-by: Konstantin Ryabitsev <mricon@kernel.org>
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r--scan-tree.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/scan-tree.c b/scan-tree.c index 2684b44..7cd8f08 100644 --- a/scan-tree.c +++ b/scan-tree.c
@@ -148,14 +148,14 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
148 } 148 }
149 149
150 if (ctx.cfg.section_from_path) { 150 if (ctx.cfg.section_from_path) {
151 n = ctx.cfg.section_from_path; 151 n = ctx.cfg.section_from_path;
152 if (n > 0) { 152 if (n > 0) {
153 slash = rel.buf; 153 slash = rel.buf - 1;
154 while (slash && n && (slash = strchr(slash, '/'))) 154 while (slash && n && (slash = strchr(slash + 1, '/')))
155 n--; 155 n--;
156 } else { 156 } else {
157 slash = rel.buf + rel.len; 157 slash = rel.buf + rel.len;
158 while (slash && n && (slash = xstrrchr(rel.buf, slash, '/'))) 158 while (slash && n && (slash = xstrrchr(rel.buf, slash - 1, '/')))
159 n++; 159 n++;
160 } 160 }
161 if (slash && !n) { 161 if (slash && !n) {