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

[PATCH 4/8 v6] gitweb: Check that $site_header etc. are defined before using them

From
Jakub Narebski <jnareb@gmail.com>
Date
Jan 30, 2010, 22:30 UTC
Message-ID
<1264890645-28310-5-git-send-email-jnareb@gmail.com>
In-Reply-To
<1264890645-28310-1-git-send-email-jnareb@gmail.com>
From: John 'Warthog9' Hawley <warthog9@kernel.org>

If one of $site_header, $site_footer or $home_text is not defined you get extraneous errors in the web logs, for example (line wrapped for better readibility):

 [Wed Jan 13 16:55:42 2010] [error] [client ::1] [Wed Jan 13 16:55:42 2010]
 gitweb.cgi: Use of uninitialized value $site_header in -f at
 /var/www/gitweb/gitweb.cgi line 3287., referer: http://git/gitweb.cgi
This ensures that those variables are defined before trying to use it.

Note that such error can happen only because of an error in gitweb config file; building gitweb.cgi can make mentioned variables holding empty string (it is even the default), but they not undefined.

Signed-off-by: John 'Warthog9' Hawley <warthog9@kernel.org>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Changes from version from 'Gitweb caching v5' and
  git://git.kernel.org/pub/scm/git/warthog9/gitweb.git gitweb-ml-v5
* Check explicitly that $site_header is defined, and not only that it
  is false-ish
* Check also for $site_footer and $home_text being defined
* Slightly more detailed commit message

I have decided not to protect against undefined $projects_list, as such check would have to be more complicated and quite different from checks for $site_header, $site_footer and $home_text.

Note that it is purely defensive programming, as this should not happen unless there are very strange errors in gitweb config file.

 gitweb/gitweb.perl |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index e2522cc..a4148d3 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3254,7 +3254,7 @@ EOF
 	print "</head>\n" .
 	      "<body>\n";
 
-	if (-f $site_header) {
+	if (defined $site_header && -f $site_header) {
 		insert_file($site_header);
 	}
 
@@ -3355,7 +3355,7 @@ sub git_footer_html {
 		print "</div>\n"; # class="page_footer"
 	}
 
-	if (-f $site_footer) {
+	if (defined $site_footer && -f $site_footer) {
 		insert_file($site_footer);
 	}
 
@@ -4781,7 +4781,7 @@ sub git_project_list {
 	}
 
 	git_header_html();
-	if (-f $home_text) {
+	if (defined $home_text && -f $home_text) {
 		print "<div class=\"index_include\">\n";
 		insert_file($home_text);
 		print "</div>\n";
-- 
1.6.6.1
Previous: Jakub NarebskiNext: Jakub Narebski
Message 5 of 14 in “Miscelanous gitweb improvements from 'Gitweb caching v5' by J.H.”
  1. 0/8 Miscelanous gitweb improvements from 'Gitweb caching v5' by J.H.Jakub Narebski, Jan 30, 2010
  2. 1/8 gitweb: Make running t9501 test with '--debug' reliable and usableJakub Narebski, Jan 30, 2010
  3. 2/8 gitweb: Load checkingJakub Narebski, Jan 30, 2010
  4. 3/8 gitweb: Makefile improvementsJakub Narebski, Jan 30, 2010
  5. 4/8 gitweb: Check that $site_header etc. are defined before using themJakub Narebski, Jan 30, 2010
  6. 5/8 gitweb: add a get function to compliment print_local_timeJakub Narebski, Jan 30, 2010
  7. Junio C HamanoJan 31, 2010
  8. 6/8 gitweb: add a get function to compliment print_sort_thJakub Narebski, Jan 30, 2010
  9. 7/8 gitweb: Add optional extra parameter to die_error, for extended explanationJakub Narebski, Jan 30, 2010
  10. 8/8 gitweb: Add an option to force version matchJakub Narebski, Jan 30, 2010
  11. J.H.Feb 2, 2010
  12. Jakub NarebskiFeb 2, 2010
  13. Junio C HamanoFeb 2, 2010
  14. Junio C HamanoFeb 2, 2010

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.