Permalink
Browse files

Move InstawebHandler initialization after validity checks.

Creating an instaweb handler will run MakeRequestUrl, which assumes that
request->unparsed_uri is non-null.  So move the creation to after where
we check that it's non-null.  To be safe, move it all the way down to
where it's first needed, in case some other validity checks end up being
relevant.

Fixes #1248
  • Loading branch information...
jeffkaufman committed Jan 21, 2016
1 parent 07bd70c commit befa49422be64d0ab69aa5adf79005c9ec744f73
Showing with 14 additions and 3 deletions.
  1. +6 −0 pagespeed/apache/instaweb_context.cc
  2. +3 −3 pagespeed/apache/mod_instaweb.cc
  3. +5 −0 pagespeed/system/system_test.sh
@@ -365,6 +365,12 @@ const char* InstawebContext::MakeRequestUrl(
// as an absolute URL. So we check if request->unparsed_uri is already
// an absolute URL first. If so, use it as-is, otherwise ap_construct_url().
if (url == NULL) {
if (request->unparsed_uri == NULL) {
LOG(DFATAL) <<
"build_context_for_request should verify unparsed_uri is non-null.";
return NULL;
}

GoogleUrl gurl(request->unparsed_uri);
if (gurl.IsAnyValid()) {
url = apr_pstrdup(request->pool, request->unparsed_uri);
@@ -378,9 +378,6 @@ InstawebContext* build_context_for_request(request_rec* request) {
return NULL;
}

InstawebHandler instaweb_handler(request);
const RewriteOptions* options = instaweb_handler.options();

if (request->unparsed_uri == NULL) {
// TODO(jmarantz): consider adding Debug message if unparsed_uri is NULL,
// possibly of request->the_request which was non-null in the case where
@@ -445,6 +442,9 @@ InstawebContext* build_context_for_request(request_rec* request) {
return NULL;
}

InstawebHandler instaweb_handler(request);
const RewriteOptions* options = instaweb_handler.options();

const GoogleUrl& stripped_gurl = instaweb_handler.stripped_gurl();
if (!stripped_gurl.IsWebValid()) {
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, request,
@@ -2287,3 +2287,8 @@ start_test AddResourceHeaders works for pagespeed resources.
URL="$TEST_ROOT/compressed/hello_js.custom_ext.pagespeed.ce.HdziXmtLIV.txt"
HTML_HEADERS=$($WGET_DUMP $URL)
check_from "$HTML_HEADERS" grep -q "^X-Foo: Bar"

start_test long url handling
# This is an extremely long url, enough that it should give a 4xx server error.
OUT=$($CURL -sS -D- "$TEST_ROOT/$(head -c 10000 < /dev/zero | tr '\0' 'a')")
check_from "$OUT" grep -q "414 Request-URI Too Large"

0 comments on commit befa494

Please sign in to comment.