Skip to content

Fix handling of truncated legacy errorpage %codes#2411

Closed
rousskov wants to merge 2 commits intosquid-cache:masterfrom
measurement-factory:SQUID-111-errorpage-build-trailing-pct
Closed

Fix handling of truncated legacy errorpage %codes#2411
rousskov wants to merge 2 commits intosquid-cache:masterfrom
measurement-factory:SQUID-111-errorpage-build-trailing-pct

Conversation

@rousskov
Copy link
Copy Markdown
Contributor

When build.input ends with a bare percent character, we must only
copy/consume that character and increment build.input by 1, not 2.

This overread bug existed since errorpage templates were introduced in
1997 commit 9b312a1. 2010 commit 4d16918 significantly broadened the
kinds of use cases that can trigger this bug.

    noteBuildError_: ... Unsupported error page %code near %

When build.input ends with a bare percent character, we must only
copy/consume that character and increment build.input by 1, not 2.

This overread bug existed since errorpage templates were introduced in
1997 commit 9b312a1. 2010 commit 4d16918 significantly broadened the
kinds of use cases that can trigger this bug.
    errorpage.cc(1294) compileLegacyCode: %? --> '%'

Nothing was printed after the first '%' char...
@rousskov rousskov added the S-could-use-an-approval An approval may speed this PR merger (but is not required) label Apr 22, 2026
Copy link
Copy Markdown
Contributor Author

@rousskov rousskov left a comment

Choose a reason for hiding this comment

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

There is another bug implied by @jro-calif report that triggered this pull request, but that bug is very different in nature and deserves a separate fix. I hope to post the corresponding pull request within 48 hours.

Comment thread src/errorpage.cc

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.

Comment thread src/errorpage.cc

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.

Comment thread src/errorpage.cc

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.

Copy link
Copy Markdown
Contributor

@yadij yadij left a comment

Choose a reason for hiding this comment

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

LGTM

@yadij yadij added M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels backport-to-v7 maintainer has approved these changes for v7 backporting labels Apr 23, 2026
squid-anubis pushed a commit that referenced this pull request Apr 23, 2026
When build.input ends with a bare percent character, we must only
copy/consume that character and increment build.input by 1, not 2.

This overread bug existed since errorpage templates were introduced in
1997 commit 9b312a1. 2010 commit 4d16918 significantly broadened the
kinds of use cases that can trigger this bug.
@squid-anubis squid-anubis added the M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels label Apr 23, 2026
@squid-anubis squid-anubis added M-merged https://github.com/measurement-factory/anubis#pull-request-labels and removed M-waiting-staging-checks https://github.com/measurement-factory/anubis#pull-request-labels M-cleared-for-merge https://github.com/measurement-factory/anubis#pull-request-labels labels Apr 23, 2026
@squidadm
Copy link
Copy Markdown
Collaborator

queued for backport to v7

@squidadm squidadm removed the backport-to-v7 maintainer has approved these changes for v7 backporting label Apr 24, 2026
kinkie pushed a commit that referenced this pull request Apr 25, 2026
When build.input ends with a bare percent character, we must only
copy/consume that character and increment build.input by 1, not 2.

This overread bug existed since errorpage templates were introduced in
1997 commit 9b312a1. 2010 commit 4d16918 significantly broadened the
kinds of use cases that can trigger this bug.
@rousskov
Copy link
Copy Markdown
Contributor Author

There is another bug implied by @jro-calif report that triggered this pull request, but that bug is very different in nature and deserves a separate fix. I hope to post the corresponding pull request within 48 hours.

Finally done at #2416. It took me a few iterations to find the correct solution and polish it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

M-merged https://github.com/measurement-factory/anubis#pull-request-labels S-could-use-an-approval An approval may speed this PR merger (but is not required)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants