From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Subject: [PATCH (BUGFIX)] gitweb: Handle invalid regexp in regexp search
Date: Tue, 28 Feb 2012 19:41:47 +0100 [thread overview]
Message-ID: <20120228183919.26435.86795.stgit@localhost.localdomain> (raw)
When using regexp search ('sr' parameter / $search_use_regexp variable
is true), check first that regexp is valid.
Without this patch we would get an error from Perl during search (if
searching is performed by gitweb), or highlighting matches substring
(if applicable), if user provided invalid regexp... which means broken
HTML, with error page (including HTTP headers) generated after gitweb
already produced some output.
Add test that illustrates such error: for example for regexp "*\.git"
we would get the following error:
Quantifier follows nothing in regex; marked by <-- HERE in m/* <-- HERE \.git/
at /var/www/cgi-bin/gitweb.cgi line 3084.
Reported-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
See "Re: gitweb: (potential) problems with new installation"
http://thread.gmane.org/gmane.comp.version-control.git/191746
gitweb/gitweb.perl | 11 ++++++++++-
t/t9501-gitweb-standalone-http-status.sh | 10 ++++++++++
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1fc5361..22ad279 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1081,7 +1081,16 @@ sub evaluate_and_validate_params {
if (length($searchtext) < 2) {
die_error(403, "At least two characters are required for search parameter");
}
- $search_regexp = $search_use_regexp ? $searchtext : quotemeta $searchtext;
+ if ($search_use_regexp) {
+ $search_regexp = $searchtext;
+ if (!eval { qr/$search_regexp/; 1; }) {
+ (my $error = $@) =~ s/ at \S+ line \d+.*\n?//;
+ die_error(400, "Invalid search regexp '$search_regexp'",
+ esc_html($error));
+ }
+ } else {
+ $search_regexp = quotemeta $searchtext;
+ }
}
}
diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh
index 26102ee..31076ed 100755
--- a/t/t9501-gitweb-standalone-http-status.sh
+++ b/t/t9501-gitweb-standalone-http-status.sh
@@ -134,4 +134,14 @@ our $maxload = undef;
EOF
+# ----------------------------------------------------------------------
+# invalid arguments
+
+test_expect_success 'invalid arguments: invalid regexp (in project search)' '
+ gitweb_run "a=project_list;s=*\.git;sr=1" &&
+ grep "Status: 400" gitweb.headers &&
+ grep "400 - Invalid.*regexp" gitweb.body
+'
+test_debug 'cat gitweb.headers'
+
test_done
next reply other threads:[~2012-02-28 18:41 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-28 18:41 Jakub Narebski [this message]
2012-02-28 19:45 ` [PATCH (BUGFIX)] gitweb: Handle invalid regexp in regexp search Junio C Hamano
2012-02-29 15:56 ` Jakub Narebski
2012-03-02 19:44 ` Ramsay Jones
2012-03-02 22:34 ` [PATCH (BUGFIX)] gitweb: Fix fixed string (non-regexp) project search Jakub Narebski
2012-03-03 0:08 ` Junio C Hamano
2012-03-03 10:55 ` Jakub Narebski
2012-03-04 9:35 ` [PATCH (for maint)] " Jakub Narebski
2012-03-05 5:16 ` Junio C Hamano
2012-03-05 8:59 ` Jakub Narebski
2012-03-05 17:01 ` Junio C Hamano
2012-03-05 23:27 ` Junio C Hamano
2012-03-06 11:59 ` Jakub Narebski
2012-03-04 18:00 ` [PATCH (BUGFIX)] " Jakub Narebski
2012-03-04 23:08 ` Junio C Hamano
2012-03-05 9:03 ` Jakub Narebski
2012-03-05 19:06 ` Ramsay Jones
2012-03-06 12:40 ` Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120228183919.26435.86795.stgit@localhost.localdomain \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=ramsay@ramsay1.demon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).