git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] gitweb: Return plain booleans in validation methods

From
Krzesimir Nowak <krzesimir@endocode.com>
Date
Dec 4, 2013, 13:43 UTC
Message-ID
<1386164583-14109-4-git-send-email-krzesimir@endocode.com>
In-Reply-To
<1386164583-14109-1-git-send-email-krzesimir@endocode.com>

Users of validate_* passing "0" might get failures on correct name because of coercion of "0" to false in code like: die_error(500, "invalid ref") unless (check_ref_format ("0"));

Signed-off-by: Krzesimir Nowak <krzesimir@endocode.com>
---
 gitweb/gitweb.perl | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 67415b9..3434602 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1419,63 +1419,68 @@ sub href {
 ## validation, quoting/unquoting and escaping
 
 sub validate_action {
-	my $input = shift || return undef;
-	return undef unless exists $actions{$input};
-	return $input;
+	my $input = shift;
+
+	return 0 unless defined $input;
+	return 0 unless exists $actions{$input};
+	return 1;
 }
 
 sub validate_project {
-	my $input = shift || return undef;
+	my $input = shift;
+
+	return 0 unless defined $input;
 	if (!validate_pathname($input) ||
 		!(-d "$projectroot/$input") ||
 		!check_export_ok("$projectroot/$input") ||
 		($strict_export && !project_in_list($input))) {
-		return undef;
+		return 0;
 	} else {
-		return $input;
+		return 1;
 	}
 }
 
 sub validate_pathname {
-	my $input = shift || return undef;
+	my $input = shift;
 
+	return 0 unless defined $input;
 	# no '.' or '..' as elements of path, i.e. no '.' nor '..'
 	# at the beginning, at the end, and between slashes.
 	# also this catches doubled slashes
 	if ($input =~ m!(^|/)(|\.|\.\.)(/|$)!) {
-		return undef;
+		return 0;
 	}
 	# no null characters
 	if ($input =~ m!\0!) {
-		return undef;
+		return 0;
 	}
-	return $input;
+	return 1;
 }
 
 sub check_ref_format {
-	my $input = shift || return undef;
+	my $input = shift;
 
+	return 0 unless defined $input;
 	# restrictions on ref name according to git-check-ref-format
 	if ($input =~ m!(/\.|\.\.|[\000-\040\177 ~^:?*\[]|/$)!) {
-		return undef;
+		return 0;
 	}
-	return $input;
+	return 1;
 }
 
 sub validate_refname {
-	my $input = shift || return undef;
+	my $input = shift;
 
+	return undef unless defined $input;
 	# textual hashes are O.K.
 	if ($input =~ m/^[0-9a-fA-F]{40}$/) {
-		return $input;
+		return 1;
 	}
 	# it must be correct pathname
-	$input = validate_pathname($input)
-		or return undef;
+	validate_pathname($input) or return 0;
 	# check git-check-ref-format restrictions
-	check_ref_format($input)
-		or return undef;
-	return $input;
+	check_ref_format($input) or return 0;
+	return 1;
 }
 
 # decode sequences of octets in utf8 into Perl's internal form,
-- 
1.8.3.1
Previous: Krzesimir NowakNext: Jakub Narębski
Message 15 of 32 in “Show extra branch refs in gitweb v6”
  1. 0/5 Show extra branch refs in gitweb v6Krzesimir Nowak, Dec 4, 2013
  2. 1/5 gitweb: Add a comment explaining the meaning of $/Krzesimir Nowak, Dec 4, 2013
  3. Jakub NarębskiDec 4, 2013
  4. Krzesimir NowakDec 4, 2013
  5. Martin LanghoffDec 4, 2013
  6. Junio C HamanoDec 4, 2013
  7. Krzesimir NowakDec 5, 2013
  8. Jakub NarębskiDec 4, 2013
  9. Jakub NarębskiDec 4, 2013
  10. 2/5 gitweb: Move check-ref-format code into separate functionKrzesimir Nowak, Dec 4, 2013
  11. Jakub NarębskiDec 4, 2013
  12. Krzesimir NowakDec 5, 2013
  13. Junio C HamanoDec 4, 2013
  14. Krzesimir NowakDec 5, 2013
  15. 3/5 gitweb: Return plain booleans in validation methodsKrzesimir Nowak, Dec 4, 2013
  16. Jakub NarębskiDec 4, 2013
  17. Junio C HamanoDec 4, 2013
  18. Krzesimir NowakDec 5, 2013
  19. Junio C HamanoDec 5, 2013
  20. Jakub NarębskiDec 5, 2013
  21. Junio C HamanoDec 5, 2013
  22. 4/5 gitweb: Add a feature for adding more branch refsKrzesimir Nowak, Dec 4, 2013
  23. Jakub NarębskiDec 4, 2013
  24. Krzesimir NowakDec 5, 2013
  25. Jakub NarębskiDec 5, 2013
  26. Krzesimir NowakDec 10, 2013
  27. Junio C HamanoDec 10, 2013
  28. Jakub NarębskiDec 10, 2013
  29. Junio C HamanoDec 10, 2013
  30. 5/5 gitweb: Denote non-heads, non-remotes branchesKrzesimir Nowak, Dec 4, 2013
  31. Jakub NarębskiDec 4, 2013
  32. Junio C HamanoDec 4, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.