Skip to content

redis: fix uncaught exception in inline quoted hex escape parsing - #48177

Open
kalt2212 wants to merge 3 commits into
envoyproxy:mainfrom
kalt2212:fix-redis-stoul-crash
Open

kalt2212 wants to merge 3 commits into
envoyproxy:mainfrom
kalt2212:fix-redis-stoul-crash

Conversation

@kalt2212

@kalt2212 kalt2212 commented Oct 9, 2026

Copy link
Copy Markdown

Summary

Fixes an uncaught std::invalid_argument exception in the Redis inline command decoder (source/extensions/filters/network/common/redis/codec_impl.cc, state InlineStringQuotedEscapeHex).

Details

Commit f8f1768 added a bounds check before the hex-escape decode, but it is not sufficient: s[s.size() - 3] == 'x' can match an 'x' that is a literal character from earlier in the token rather than the escape introducer. Example trigger: the quoted inline token "xx\x41".

In that case the two characters passed to std::stoul(..., 16) are not hex digits, so stoul throws std::invalid_argument. The decoder's callers only catch ProtocolError, so the exception propagates out of onData and terminates the process — an unauthenticated remote crash.

The patch validates both characters with std::isxdigit before calling stoul, and throws ProtocolError("invalid hex escape in request") instead, which the existing machinery handles gracefully (connection closed, no crash).

Testing

  • Reproduced the crash with a minimal decoder harness feeding "xx\x41" (process terminated via uncaught exception before the patch).
  • After the patch, the same input raises ProtocolError and the connection is closed cleanly.
  • Existing redis codec unit tests unaffected.

AI tool use disclosure: AI was used in part for code audit and patch drafting.

@repokitteh-read-only

Copy link
Copy Markdown

Hi @kalt2212, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #48177 was opened by kalt2212.

see: more, trace.

@kalt2212
kalt2212 had a problem deploying to external-contributors October 9, 2026 14:49 — with GitHub Actions Error
@KBaichoo

Copy link
Copy Markdown
Contributor

/assign @dinesh-murugiah

@kalt2212 can you add a regression test?

@KBaichoo

Copy link
Copy Markdown
Contributor

Signed-off-by: Kalt2212 <adrimg3196@gmail.com>
A literal 'x' earlier in the token must not be mistaken for the hex-escape
introducer. Requested by Kevin Baichoo.

Signed-off-by: Kalt2212 <adrimg3196@gmail.com>
@kalt2212
kalt2212 force-pushed the fix-redis-stoul-crash branch from 789c17e to a6b5fff Compare October 16, 2026 18:51
@kalt2212
kalt2212 temporarily deployed to external-contributors October 16, 2026 18:53 — with GitHub Actions Inactive
yanavlasov
yanavlasov previously approved these changes Oct 22, 2026

@yanavlasov yanavlasov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will need to be converted to use absl::Status and remove exceptions.

@yanavlasov
yanavlasov enabled auto-merge (squash) October 22, 2026 01:38
@yanavlasov

Copy link
Copy Markdown
Contributor

@kalt2212 the spell checker had failed. https://github.com/envoyproxy/envoy/actions/runs/39706984100/job/119589284676#step:20:727

/wait

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions Bot added the stale stalebot believes this issue/PR has not been touched recently label Nov 21, 2026
@kalt2212

Copy link
Copy Markdown
Author

Hi @dinesh-murugiah @yanavlasov, quick status update: I'm currently refining the hex escape state tracking to cleanly handle edge cases with preceding literal characters (e.g. "xx\x41") and adding additional test coverage before pinging for the final review. Will push an update shortly.

@github-actions github-actions Bot removed the stale stalebot believes this issue/PR has not been touched recently label Nov 21, 2026
Signed-off-by: Adrian Martinez Garcia <adrimg3196@gmail.com>
auto-merge was automatically disabled November 21, 2026 22:54

Head branch was pushed to by a user without write access

@kalt2212
kalt2212 requested a deployment to external-contributors November 21, 2026 22:54 — with GitHub Actions Waiting

This branch is waiting to be deployed

1 waiting deployment
external-contributors — 6158b66a Waiting Nov 21, 2026 by kalt2212 via authorize #63143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants