List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] ui-clone.c: Fix starts_with() path check
@ 2015-02-08 22:14 cgit
  2015-02-09  6:25 ` [PATCH v2] ui-clone.c: Fix " cgit
  0 siblings, 1 reply; 3+ messages in thread
From: cgit @ 2015-02-08 22:14 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] ui-clone.c: Fix path check
  2015-02-08 22:14 [PATCH] ui-clone.c: Fix starts_with() path check cgit
@ 2015-02-09  6:25 ` cgit
  2015-02-09 11:01   ` Jason
  0 siblings, 1 reply; 3+ messages in thread
From: cgit @ 2015-02-09  6:25 UTC (permalink / raw)


The starts_with() 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>
---
Using skip_prefix() might be even better here :)

 ui-clone.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2] ui-clone.c: Fix path check
  2015-02-09  6:25 ` [PATCH v2] ui-clone.c: Fix " cgit
@ 2015-02-09 11:01   ` Jason
  0 siblings, 0 replies; 3+ messages in thread
From: Jason @ 2015-02-09 11:01 UTC (permalink / raw)


Merged thanks.

Still no luck with the other bug. Working on it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20150209/1be93b88/attachment.html>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-09 11:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-08 22:14 [PATCH] ui-clone.c: Fix starts_with() path check cgit
2015-02-09  6:25 ` [PATCH v2] ui-clone.c: Fix " cgit
2015-02-09 11:01   ` Jason

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).