threads / patch / 5589

patchgitweb fix validating pg (page) parameter

Subject: [PATCH] gitweb fix validating pg (page) parameter

## tl;dr

4 messages between Sep 17, 2006 and Sep 17, 2006. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

Matthias Lederhofer· Sep 17, 2006, 11:52 UTC · lore
Currently it is possible to give any string ending with a number as
page.  -1 for example is quite bad (error log shows probably 100
warnings).
---
 gitweb/gitweb.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to gitweb/gitweb.perl +1 −1
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 497129a..346c15c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -259,7 +259,7 @@ if (defined $hash_parent_base) {
 
 our $page = $cgi->param('pg');
 if (defined $page) {
-	if ($page =~ m/[^0-9]$/) {
+	if ($page =~ m/[^0-9]/) {
 		die_error(undef, "Invalid page parameter");
 	}
 }
-- 
1.4.2.1.ge767
Junio C Hamano· Sep 17, 2006, 21:21 UTC · re: Matthias Lederhofer · lore

Re: [PATCH] gitweb fix validating pg (page) parameter

Matthias Lederhofer <matled@gmx.net> writes:
Show 13 quoted lines
> Currently it is possible to give any string ending with a number as
> page.  -1 for example is quite bad (error log shows probably 100
> warnings).
>
> @@ -259,7 +259,7 @@ if (defined $hash_parent_base) {
>  
>  our $page = $cgi->param('pg');
>  if (defined $page) {
> -	if ($page =~ m/[^0-9]$/) {
> +	if ($page =~ m/[^0-9]/) {
>  		die_error(undef, "Invalid page parameter");
>  	}
>  }

Are we complaining if $page is not a validly formatted number here? If so why not

	unless ($page =~ /^\d+$/ && 1 <= $page) {
        	barf(...);
	}
???
Matthias Lederhofer· Sep 17, 2006, 21:38 UTC · re: Junio C Hamano · lore

Re: [PATCH] gitweb fix validating pg (page) parameter

Junio C Hamano <junkio@cox.net> wrote:
Show 22 quoted lines
> Matthias Lederhofer <matled@gmx.net> writes:
> 
> > Currently it is possible to give any string ending with a number as
> > page.  -1 for example is quite bad (error log shows probably 100
> > warnings).
> >
> > @@ -259,7 +259,7 @@ if (defined $hash_parent_base) {
> >  
> >  our $page = $cgi->param('pg');
> >  if (defined $page) {
> > -	if ($page =~ m/[^0-9]$/) {
> > +	if ($page =~ m/[^0-9]/) {
> >  		die_error(undef, "Invalid page parameter");
> >  	}
> >  }
> 
> Are we complaining if $page is not a validly formatted number
> here?  If so why not
> 
> 	unless ($page =~ /^\d+$/ && 1 <= $page) {
>         	barf(...);
> 	}

The first page seems to have number 0. After removing the 1 <= $page this code should do the same as my patch, apply whatever you think is easier to read (I prefer if over unless most of the time).

Junio C Hamano· Sep 17, 2006, 21:45 UTC · re: Matthias Lederhofer · lore

Re: [PATCH] gitweb fix validating pg (page) parameter

Matthias Lederhofer <matled@gmx.net> writes:
Show 5 quoted lines
>> > +	if ($page =~ m/[^0-9]/) {
>...
> The first page seems to have number 0.  After removing the 1 <= $page
> this code should do the same as my patch, apply whatever you think is
> easier to read (I prefer if over unless most of the time).

Ah, I did not notice we call the first page 0; barfing on any non-digit in the string like you do sounds quite sane.

Thanks.

← back to recent threads