]> gitweb.ps.run Git - ps-cgit/commitdiff
Fix section-from-path > 1
authorLukas Fleischer <cgit@cryptocrack.de>
Fri, 28 Jun 2013 08:58:14 +0000 (08:58 +0000)
committerJason A. Donenfeld <Jason@zx2c4.com>
Mon, 12 Aug 2013 19:14:11 +0000 (13:14 -0600)
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>
scan-tree.c

index 2684b446961686c9d48f785fc990bcbcd76db8e6..7cd8f08672e1f79c7b71432d4aa180a2a7ce8180 100644 (file)
@@ -148,14 +148,14 @@ static void add_repo(const char *base, struct strbuf *path, repo_config_fn fn)
        }
 
        if (ctx.cfg.section_from_path) {
-               n  = ctx.cfg.section_from_path;
+               n = ctx.cfg.section_from_path;
                if (n > 0) {
-                       slash = rel.buf;
-                       while (slash && n && (slash = strchr(slash, '/')))
+                       slash = rel.buf - 1;
+                       while (slash && n && (slash = strchr(slash + 1, '/')))
                                n--;
                } else {
                        slash = rel.buf + rel.len;
-                       while (slash && n && (slash = xstrrchr(rel.buf, slash, '/')))
+                       while (slash && n && (slash = xstrrchr(rel.buf, slash - 1, '/')))
                                n++;
                }
                if (slash && !n) {