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

[PATCH] gitweb: Avoid "Use of uninitialized value" errors (written to logs)

From
Jakub Narebski <jnareb@gmail.com>
Date
May 11, 2007, 23:35 UTC
Message-ID
<200705120135.30150.jnareb@gmail.com>

Try to avoid "Use of uninitialized value ..." errors, due to bad revision, incorrect filename, wrong object id, bad file etc. (wrong value of 'h', 'hb', 'f', etc. parameters). This avoids polluting web server errors log.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This is a bit of "bandaid" patch, as if possible the callers should
be corrected, and should check if there is something to pass along.
 gitweb/gitweb.perl |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 21864c6..afa0056 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -594,6 +594,9 @@ sub esc_html ($;%) {
 	my $str = shift;
 	my %opts = @_;
 
+	# empty or undefined
+	return $str unless $str;
+
 	$str = decode_utf8($str);
 	$str = $cgi->escapeHTML($str);
 	if ($opts{'-nbsp'}) {
@@ -1059,6 +1062,7 @@ sub git_get_hash_by_path {
 		or die_error(undef, "Open git-ls-tree failed");
 	my $line = <$fd>;
 	close $fd or return undef;
+	$line or return undef;
 
 	#'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa	panic.c'
 	$line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/;
@@ -1377,7 +1381,7 @@ sub parse_commit_text {
 	pop @commit_lines; # Remove '\0'
 
 	my $header = shift @commit_lines;
-	if (!($header =~ m/^[0-9a-fA-F]{40}/)) {
+	if (!defined $header || $header !~ m/^[0-9a-fA-F]{40}/) {
 		return;
 	}
 	($co{'id'}, my @parents) = split ' ', $header;
-- 
1.5.1.3
Next: Junio C Hamano
Message 1 of 7 in “gitweb: Avoid "Use of uninitialized value" errors (written to logs)”
  1. gitweb: Avoid "Use of uninitialized value" errors (written to logs)Jakub Narebski, May 11, 2007
  2. Junio C HamanoMay 12, 2007
  3. gitweb: Check if requested object existsJakub Narebski, May 12, 2007
  4. gitweb: Fix "Use of unitialized value" warnings in empty repositoryJakub Narebski, May 13, 2007
  5. Junio C HamanoMay 13, 2007
  6. gitweb: Test if $from_id and $to_id are defined before comparisonJakub Narebski, May 12, 2007
  7. Junio C HamanoMay 12, 2007

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.