AmSdp::parse: contain parser exceptions instead of aborting on malformed SDP#555
Open
hecko wants to merge 1 commit into
Open
AmSdp::parse: contain parser exceptions instead of aborting on malformed SDP#555hecko wants to merge 1 commit into
hecko wants to merge 1 commit into
Conversation
parse_sdp_line_ex() and its helpers construct std::string objects from raw pointer arithmetic, e.g. string(connection_line, line_len - 7) and string(line, int(next - line) - 2), with no lower-bound check. On a truncated or malformed SDP body those length expressions underflow to a huge size_t and std::string throws std::length_error (or out_of_range). AmSdp::parse() runs directly on attacker-supplied INVITE/UPDATE offer and answer bodies, and its callers do not catch, so an unhandled throw propagates out and terminates the process -- a remotely-triggerable DoS. Wrap parse_sdp_line_ex() in try/catch and report a parse failure (return non-zero, matching the existing error convention) instead of letting the exception escape. Backported from yeti-switch/sems, which guards the same parse_sdp_line_ex() call with try/catch for std::out_of_range and generic exceptions.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens SDP parsing against malformed/truncated attacker-supplied SDP bodies by containing exceptions thrown during parsing, preventing an unhandled exception from terminating the SIP processing process (remotely-triggerable DoS).
Changes:
- Wrap
parse_sdp_line_ex()insideAmSdp::parse()intry/catchto prevent exceptions from escaping the SIP path. - Log parsing exceptions and return a non-zero parse error (consistent with
AmSdp::parse()’s!=0error contract). - Add in-code rationale documenting why exception containment is required for security/robustness.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
parse_sdp_line_ex()and its helpers in core/AmSdp.cpp buildstd::stringobjects from raw pointer arithmetic with no lower-bound guard, for example:line_lenis asize_t. On a truncated or malformed line (e.g. ac=line shorter than the assumedIN IPxprefix)line_len - 7underflows to a huge value, andstd::stringthrowsstd::length_error. The pointer-difference forms can likewise go negative and convert to a hugesize_t.AmSdp::parse()is called directly on attacker-suppliedINVITE/UPDATEoffer and answer bodies, and its callers do not catch. An unhandled throw propagates out of the SIP processing path and terminates the process — a remotely-triggerable DoS via a single crafted SDP body.Fix
Wrap the
parse_sdp_line_ex()call in try/catch and report a parse failure (return non-zero, matching the file's existing error-return convention) instead of letting the exception escape:<stdexcept>is already included. No behavioural change for well-formed SDP.Provenance
Backported from yeti-switch/sems, which guards the same
parse_sdp_line_ex()call with try/catch forstd::out_of_rangeand generic exceptions. Thanks to the yeti-switch maintainers for the fix.Generated by Claude Code