Skip to content

Parse remote protocol integers without throwing - #1166

Open
xusheng6 wants to merge 1 commit into
devfrom
test_safe_int_parsing
Open

Parse remote protocol integers without throwing#1166
xusheng6 wants to merge 1 commit into
devfrom
test_safe_int_parsing

Conversation

@xusheng6

@xusheng6 xusheng6 commented Aug 3, 2026

Copy link
Copy Markdown
Member

Add RspConnector::ParseInt (based on std::from_chars) and use it instead of std::stoi/stoull when parsing data from the remote debug stub, so malformed packets can no longer crash the process. Also guard short-packet substr/index accesses in PacketToUnorderedMap.

Fixes #1164

std::stoi/stol/stoull raise std::invalid_argument or std::out_of_range
on malformed input. The RSP/GDB adapters called them directly on data
received from the remote debug stub, so a malformed packet could crash
the process with an uncaught exception. Add RspConnector::ParseInt, a
std::from_chars-based helper that returns a fallback value instead, and
use it at all unguarded call sites. Also guard the packet substr/index
accesses in PacketToUnorderedMap against short packets.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@xusheng6
xusheng6 requested a review from plafosse August 3, 2026 18:44
@plafosse

plafosse commented Aug 3, 2026

Copy link
Copy Markdown
Member

Why is it ok for all these sites to just default to 0 on failure? Seems like some errors should be raised or warnings displayed when the failure conditions occur?

@xusheng6

xusheng6 commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

Why is it ok for all these sites to just default to 0 on failure? Seems like some errors should be raised or warnings displayed when the failure conditions occur?

Usually when this happens, the communication already deviated from the expected way in an irrecoverable way (e.g., the GDB stub and our adapter has a different assumption of the RSP protocol), so the actual value does not matter as long we we do not crash ourselves.

I think we can add a warning when this happens so as to assist troubleshooting, do you want that to be done?

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.

Malformed remote stub data can crash via unguarded std::stoi/stoull

2 participants