List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] Disallow downloading disabled snapshot formats
@ 2014-01-10 14:38 cgit
  2014-01-10 14:50 ` john
  2014-01-10 16:11 ` Jason
  0 siblings, 2 replies; 5+ messages in thread
From: cgit @ 2014-01-10 14:38 UTC (permalink / raw)


We did only display enabled snapshot formats but we did not prevent from
downloading disabled formats when requested. Fix this by adding an
appropriate check.

Also, add a test case that checks whether downloading disabled snapshot
formats is denied, as expected.

Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
 tests/t0107-snapshot.sh | 5 +++++
 ui-snapshot.c           | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
index 6cf7aaa..01e8d22 100755
--- a/tests/t0107-snapshot.sh
+++ b/tests/t0107-snapshot.sh
@@ -79,4 +79,9 @@ test_expect_success UNZIP 'verify unzipped file-5' '
 	test_line_count = 1 master/file-5
 '
 
+test_expect_success 'try to download a disabled snapshot format' '
+	cgit_url "foo/snapshot/master.tar.xz" |
+	grep "Unsupported snapshot format"
+'
+
 test_done
diff --git a/ui-snapshot.c b/ui-snapshot.c
index 8f82119..ab20a4a 100644
--- a/ui-snapshot.c
+++ b/ui-snapshot.c
@@ -205,7 +205,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
 	}
 
 	f = get_format(filename);
-	if (!f) {
+	if (!f || (snapshots & f->bit) == 0) {
 		show_error("Unsupported snapshot format: %s", filename);
 		return;
 	}
-- 
1.8.5.2



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

* [PATCH] Disallow downloading disabled snapshot formats
  2014-01-10 14:38 [PATCH] Disallow downloading disabled snapshot formats cgit
@ 2014-01-10 14:50 ` john
  2014-01-10 15:02   ` cgit
  2014-01-10 16:11 ` Jason
  1 sibling, 1 reply; 5+ messages in thread
From: john @ 2014-01-10 14:50 UTC (permalink / raw)


On Fri, Jan 10, 2014 at 03:38:06PM +0100, Lukas Fleischer wrote:
> We did only display enabled snapshot formats but we did not prevent from
> downloading disabled formats when requested. Fix this by adding an
> appropriate check.
> 
> Also, add a test case that checks whether downloading disabled snapshot
> formats is denied, as expected.
> 
> Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
> ---
>  tests/t0107-snapshot.sh | 5 +++++
>  ui-snapshot.c           | 2 +-
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/t0107-snapshot.sh b/tests/t0107-snapshot.sh
> index 6cf7aaa..01e8d22 100755
> --- a/tests/t0107-snapshot.sh
> +++ b/tests/t0107-snapshot.sh
> @@ -79,4 +79,9 @@ test_expect_success UNZIP 'verify unzipped file-5' '
>  	test_line_count = 1 master/file-5
>  '
>  
> +test_expect_success 'try to download a disabled snapshot format' '
> +	cgit_url "foo/snapshot/master.tar.xz" |
> +	grep "Unsupported snapshot format"

I really dislike seeing pipes in the test suite.  Can we redirect to
file instead and then grep the file?  This helps ensure that the exit
code from CGit is correct (I don't know if we expect it to be zero or
non-zero here, but if the latter then at least test_must_fail checks
that the process didn't segfault - I suspect it should be zero though).

> +'
> +
>  test_done
> diff --git a/ui-snapshot.c b/ui-snapshot.c
> index 8f82119..ab20a4a 100644
> --- a/ui-snapshot.c
> +++ b/ui-snapshot.c
> @@ -205,7 +205,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
>  	}
>  
>  	f = get_format(filename);
> -	if (!f) {
> +	if (!f || (snapshots & f->bit) == 0) {
>  		show_error("Unsupported snapshot format: %s", filename);
>  		return;
>  	}


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

* [PATCH] Disallow downloading disabled snapshot formats
  2014-01-10 14:50 ` john
@ 2014-01-10 15:02   ` cgit
  0 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2014-01-10 15:02 UTC (permalink / raw)


On Fri, 10 Jan 2014 at 15:50:14, John Keeping wrote:
> On Fri, Jan 10, 2014 at 03:38:06PM +0100, Lukas Fleischer wrote:
> [...]
> > +test_expect_success 'try to download a disabled snapshot format' '
> > +     cgit_url "foo/snapshot/master.tar.xz" |
> > +     grep "Unsupported snapshot format"
> 
> I really dislike seeing pipes in the test suite.  Can we redirect to
> file instead and then grep the file?  This helps ensure that the exit
> code from CGit is correct (I don't know if we expect it to be zero or
> non-zero here, but if the latter then at least test_must_fail checks
> that the process didn't segfault - I suspect it should be zero though).

Does this matter here at all? If cgit_url fails in any (unpredictable)
way, e.g. segfaults, it probably won't print the string "Unsupported
snapshot format" and the whole test case will fail. The Git test suite
itself also uses grep(1) with a pipe several times. I agree that we
shouldn't use pipes when inverting the result (looking for non-existent
patterns), though.

> 
> > +'
> > +
> >  test_done
> > diff --git a/ui-snapshot.c b/ui-snapshot.c
> > index 8f82119..ab20a4a 100644
> > --- a/ui-snapshot.c
> > +++ b/ui-snapshot.c
> > @@ -205,7 +205,7 @@ void cgit_print_snapshot(const char *head, const char *hex,
> >       }
> >  
> >       f = get_format(filename);
> > -     if (!f) {
> > +     if (!f || (snapshots & f->bit) == 0) {
> >               show_error("Unsupported snapshot format: %s", filename);
> >               return;
> >       }


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

* [PATCH] Disallow downloading disabled snapshot formats
  2014-01-10 14:38 [PATCH] Disallow downloading disabled snapshot formats cgit
  2014-01-10 14:50 ` john
@ 2014-01-10 16:11 ` Jason
  2014-01-10 17:14   ` cgit
  1 sibling, 1 reply; 5+ messages in thread
From: Jason @ 2014-01-10 16:11 UTC (permalink / raw)


On Fri, Jan 10, 2014 at 3:38 PM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
> We did only display enabled snapshot formats but we did not prevent from
> downloading disabled formats when requested. Fix this by adding an
> appropriate check.

Previously:
http://lists.zx2c4.com/pipermail/cgit/2012-June/000641.html
http://lists.zx2c4.com/pipermail/cgit/2012-October/000792.html


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

* [PATCH] Disallow downloading disabled snapshot formats
  2014-01-10 16:11 ` Jason
@ 2014-01-10 17:14   ` cgit
  0 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2014-01-10 17:14 UTC (permalink / raw)


On Fri, 10 Jan 2014 at 17:11:46, Jason A. Donenfeld wrote:
> On Fri, Jan 10, 2014 at 3:38 PM, Lukas Fleischer <cgit at cryptocrack.de> wrote:
> > We did only display enabled snapshot formats but we did not prevent from
> > downloading disabled formats when requested. Fix this by adding an
> > appropriate check.
> 
> Previously:
> http://lists.zx2c4.com/pipermail/cgit/2012-June/000641.html
> http://lists.zx2c4.com/pipermail/cgit/2012-October/000792.html

I was also thinking of server load. If we want to leave it as-is, we
should fix the documentation which currently says:

    repo.snapshots::
    	A mask of allowed snapshot-formats for this repo, restricted by
    	the "snapshots" global setting. Default value: <snapshots>.

There should at least be a note stating that "allowed" only means
"linked" here.


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

end of thread, other threads:[~2014-01-10 17:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-10 14:38 [PATCH] Disallow downloading disabled snapshot formats cgit
2014-01-10 14:50 ` john
2014-01-10 15:02   ` cgit
2014-01-10 16:11 ` Jason
2014-01-10 17:14   ` cgit

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).