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

[PATCHv2/RFC 2/3] gitweb: Harden parse_commit and parse_commits

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 15, 2012, 15:36 UTC
Message-ID
<1329320203-20272-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1329320203-20272-1-git-send-email-jnareb@gmail.com>

Gitweb has problems and gives errors when repository it shows is on unborn branch (HEAD doesn't point to a valid commit), but there exist other branches.

One of errors that shows in gitweb logs is undefined $commit_id in parse_commits() subroutine. Therefore we harden both parse_commit() and parse_commits() against undefined $commit_id, and against no output from git-rev-list because HEAD doesn't point to a commit.

Reported-by: rajesh boyapati <boyapatisrajesh@gmail.com>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch first appeared on git mailing list in "Fwd: Git-web error"
thread as
  [PATCH] gitweb: Harden parse_commit and parse_commits
  Message-Id: <201202081604.17187.jnareb@gmail.com>
  http://article.gmane.org/gmane.comp.version-control.git/190237
More prevention of generating warnings, rather than real fix.
 gitweb/gitweb.perl |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 0fdca5b..2eaf585 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3334,6 +3334,8 @@ sub parse_commit {
 	my ($commit_id) = @_;
 	my %co;
 
+	return unless defined $commit_id;
+
 	local $/ = "\0";
 
 	open my $fd, "-|", git_cmd(), "rev-list",
@@ -3343,7 +3345,9 @@ sub parse_commit {
 		$commit_id,
 		"--",
 		or die_error(500, "Open git-rev-list failed");
-	%co = parse_commit_text(<$fd>, 1);
+	my $commit_text = <$fd>;
+	%co = parse_commit_text($commit_text, 1)
+		if defined $commit_text;
 	close $fd;
 
 	return %co;
@@ -3353,6 +3357,7 @@ sub parse_commits {
 	my ($commit_id, $maxcount, $skip, $filename, @args) = @_;
 	my @cos;
 
+	return unless defined $commit_id;
 	$maxcount ||= 1;
 	$skip ||= 0;
 
-- 
1.7.9
Previous: Junio C HamanoNext: Jakub Narebski
Message 8 of 9 in “[PATCHv2 0/3] gitweb: Dealing with being on unborn branch”
  1. Jakub NarebskiFeb 15, 2012
  2. 1/3 gitweb: Deal with HEAD pointing to unborn branch in "heads" viewJakub Narebski, Feb 15, 2012
  3. Junio C HamanoFeb 16, 2012
  4. Jakub NarebskiFeb 16, 2012
  5. Junio C HamanoFeb 16, 2012
  6. Jakub NarebskiFeb 17, 2012
  7. Junio C HamanoFeb 17, 2012
  8. 2/3 gitweb: Harden parse_commit and parse_commitsJakub Narebski, Feb 15, 2012
  9. 3/3 gitweb: Silence stderr in parse_commit*() subroutinesJakub Narebski, Feb 15, 2012

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.