Skip to contentSkip to conversation

gitweb fix validating pg (page) parameter

PATCH In review Matthias Lederhofer 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitweb fix validating pg (page) parameter

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(-)
gitweb/gitweb.perl +1 -1
index 497129a..346c15c 100755
@@ -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");
 	}
 }
Signature · 1 line
1.4.2.1.ge767
#1 lore raw

gitweb/gitweb.perl if (defined $hash_parent_base) { · line 265

Quoted 13 lines · Matthias Lederhofer

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 +1 -1
@@ -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(...);
	}

???

#2 lore raw
Quoted 19 lines · Junio C Hamano

gitweb/gitweb.perl if (defined $hash_parent_base) { · line 265

Quoted 13 lines · Matthias Lederhofer

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 +1 -1
@@ -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

Quoted 3 lines
	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).

#3 lore raw
Quoted 5 lines · Matthias Lederhofer
Quoted 1 line

gitweb/gitweb.perl if (defined $hash_parent_base) { · line 262

Quoted 1 line
gitweb/gitweb.perl +1 -0
+	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.