Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/errorpage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,8 @@ ErrorState::compileLegacyCode(Build &build)

const auto &building_deny_info_url = build.building_deny_info_url; // a change reduction hack

const auto letter = build.input[1];
Assure(*build.input == '%');
const auto letter = build.input[1]; // may be the terminating NUL

switch (letter) {

Expand Down Expand Up @@ -1261,13 +1262,25 @@ ErrorState::compileLegacyCode(Build &build)
p = "%";
break;

case '\0':
// XXX: Partially duplicates error handling code of the `default:` case.
// TODO: Refactor bypassBuildErrorXXX() to accept `build` and determine the source of the error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not addressing this XXX/TODO in this PR to provide a surgical fix that is easier to backport.

if (building_deny_info_url)
bypassBuildErrorXXX("Bare % at the end of deny_info", build.input);
else
bypassBuildErrorXXX("Bare % at the end of error page", build.input);
p = "%";
do_quote = 0;
break;

default:
if (building_deny_info_url)
bypassBuildErrorXXX("Unsupported deny_info %code", build.input);
else if (letter != ';')
bypassBuildErrorXXX("Unsupported error page %code", build.input);
// else too many "font-size: 100%;" template errors to report

Assure(build.input[1]);
mb.append(build.input, 2);
do_quote = 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not disable quoting in this case IMO, but that is a different problem that has a much smaller impact and that is best addressed when refactoring this code to fully address other related problems.

break;
Expand All @@ -1278,7 +1291,8 @@ ErrorState::compileLegacyCode(Build &build)

assert(p);

debugs(4, 3, "%" << letter << " --> '" << p << "'" );
// TODO: Add an I/O manipulator to report non-printable chars better.
debugs(4, 3, "%" << (letter ? letter : '?') << " --> '" << p << "'" );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this hack, debugging line is truncated at the first % character. It would be better to report the NUL character instead of printing a somewhat misleading ?. This should be done while addressing the above manipulator TODO. I am not addressing this TODO in this PR to provide a surgical fix that is easier to backport.


if (do_quote)
p = html_quote(p);
Expand All @@ -1288,7 +1302,9 @@ ErrorState::compileLegacyCode(Build &build)

// TODO: Optimize by replacing mb with direct build.output usage.
build.output.append(p, strlen(p));
build.input += 2;
++build.input; // skip the parsed % character
if (letter)
++build.input; // when it was present, skip the parsed letter after %
}

void
Expand Down
Loading