[PATCH] ui-clone.c: Fix starts_with() path check

Lukas Fleischer cgit at cryptocrack.de
Sun Feb 8 23:14:07 CET 2015


The check was broken in two ways: For one thing, the parameters were
passed in the wrong order, for another thing, starts_with() returns 1 if
the string starts with the prefix (not 0).

Note that this bug existed since commit 02a545e (Add support for cloning
over http, 2008-08-06) but only pops in in corner cases.

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
Jason, I stumbled across this when trying to reproduce the bug you
reported earlier. Not sure if it is related but it's clearly a bug. One
reason why we haven't seen this occur earlier is that it only manifests
in a few rare cases (no packed refs, special requirements to repository
paths).

 ui-clone.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ui-clone.c b/ui-clone.c
index 50569d6..9b93459 100644
--- a/ui-clone.c
+++ b/ui-clone.c
@@ -63,7 +63,7 @@ static void send_file(char *path)
 	}
 	ctx.page.mimetype = "application/octet-stream";
 	ctx.page.filename = path;
-	if (!starts_with(ctx.repo->path, path))
+	if (starts_with(path, ctx.repo->path))
 		ctx.page.filename += strlen(ctx.repo->path) + 1;
 	cgit_print_http_headers();
 	html_include(path);
-- 
2.3.0



More information about the CGit mailing list