Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Move InstawebHandler initialization after validity checks.
Browse files Browse the repository at this point in the history
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 befa494
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pagespeed/apache/instaweb_context.cc
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions pagespeed/apache/mod_instaweb.cc
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pagespeed/system/system_test.sh
Expand Up @@ -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.