Summary
FreeSWITCH versions prior to 1.11.0 contain an out-of-bounds memory access in the STUN packet parser when handling attributes with inconsistent length fields.
Malformed STUN attributes can cause reads and writes past allocated buffers, potentially leading to crashes, data corruption, or code execution when untrusted traffic reaches the media processing path.
Affected context
The vulnerability occurs in the STUN packet parsing logic used within FreeSWITCH's media handling path.
It is relevant when FreeSWITCH receives STUN traffic on media legs, typically in NAT traversal or signaling/media negotiation scenarios.
The issue manifests when a STUN attribute's declared length is shorter than the size of the internal structure the parser casts the buffer to, allowing operations that extend beyond the attribute's actual bounds.
Exploit preconditions
- Attack surface: Network-accessible STUN processing on FreeSWITCH media endpoints.
- Required access: Ability to send crafted STUN packets to a FreeSWITCH instance (e.g., as a SIP/WebRTC endpoint, or from a reachable network location).
- Trigger point: Parsing of a malformed STUN attribute whose length field does not match the expected structure size.
- Why exploitation is possible: The parser trusts the declared attribute type and directly casts the underlying buffer into a structure without validating that the provided length is large enough, enabling reads and writes past the end of the legitimate per-leg media buffer.
Why this happens
The core issue stems from insufficient input validation combined with unsafe memory handling in C.
When processing STUN attributes, the code assumes that the declared attribute length is consistent with the size of the structure it is cast into, failing to enforce a minimum length check before accessing fields.
This leads to CWE-787: Out-of-Bounds Write and CWE-125: Out-of-Bounds Read, driven by CWE-20: Improper Input Validation, because untrusted network data is used directly to control memory accesses on a per-leg media buffer.
The abstract pattern is: "trusting protocol length fields and casting raw buffers to typed structures without validating that there is sufficient data for the structure's full layout."
Potential impact
- FreeSWITCH process crash, causing denial of service for affected calls or services.
- Corruption of in-memory media state or control structures.
- Potential information disclosure via out-of-bounds reads of adjacent memory.
- In some environments, potential remote code execution if the memory corruption can be precisely controlled and exploited.
General mitigation guidance
Defenses generally focus on robust bounds checking and safer memory handling for protocol parsers.
Recommended patterns include:
- Validating all protocol length fields against both the overall packet size and the minimum size required for target structures before casting or accessing fields.
- Using defensive parsing techniques that treat network input as untrusted and operate on explicit offsets and lengths rather than direct structure casts.
- Adding central helper routines for STUN attribute parsing that enforce common validation rules, instead of open-coded parsing per attribute.
- Applying strict separation between parsing buffers and internal state, copying only validated portions into well-sized structures.
- Running media processing components with least privilege and isolation (e.g., sandboxing, process separation) to limit blast radius if memory corruption occurs.
How teams detect issues like this
Detection efforts can combine code-centric and runtime-focused approaches:
- Static analysis rules to flag direct structure casts from network buffers, pointer arithmetic based on untrusted length fields, and missing bounds checks on protocol attributes.
- Code review checklists for protocol parsers that require verification of length field validation, minimum size checks, and avoidance of unsafe casts.
- Fuzz testing of STUN and related media negotiation protocols, with coverage-guided fuzzers aimed at exercising attribute parsing paths and triggering memory safety issues.
- Runtime protections (e.g., ASan in staging, hardened allocators, stack canaries) to surface out-of-bounds accesses early in testing.
- Network monitoring or test harnesses that replay malformed STUN traffic to confirm patched behavior and absence of crashes.

