fix(p2p): bound sscanf field widths in tuya_sdp.c to prevent stack overflow - #726
Merged
shiliu-yang merged 1 commit intoSep 30, 2026
Merged
Conversation
…erflow tuya_p2p_rtc_sdp_decode() parsed attacker-controlled SDP attributes with unbounded "%s" conversions into fixed-size stack buffers (wms_name, wms_id, msid, track_id, m1-m3, str_pt, str_attr, ssrc, ssrc_rtx). A malicious P2P peer could send overlong tokens in SDP lines such as "a=msid-semantic:" and overflow these buffers, corrupting the stack and potentially achieving remote code execution. Add maximum field widths (size - 1) to every %s conversion so input is safely truncated to the destination buffer size. Verified with an AddressSanitizer PoC that the original code crashes with a stack-buffer-overflow (WRITE of 201 bytes into char[65]) while the patched code parses the same malicious SDP cleanly.
maidang-xing
force-pushed
the
fix/p2p-sdp-sscanf-stack-overflow
branch
from
September 30, 2026 06:00
0df6b8a to
a0789b2
Compare
shiliu-yang
approved these changes
Sep 30, 2026
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.
Problem
tuya_p2p_rtc_sdp_decode()insrc/tuya_p2p/base_ice/src/tuya_sdp.cparses SDP lines received from the remote P2P peer usingsscanf()with unbounded%sconversions into fixed-size stack buffers:a=msid-semantic:wms_name[65],wms_id[65]a=msid:msid[65],track_id[65]a=group:BUNDLEm1[65],m2[65],m3[65]a=fmtp:str_pt[32],str_attr[256]a=ssrc-group:FIDssrc[65],ssrc_rtx[65]An attacker on the peer side controls the SDP answer and can send an arbitrarily long token in any of these lines, overflowing the stack buffers and potentially achieving remote code execution.
Fix
Add maximum field widths (
size - 1) to every%sconversion so each token is safely truncated to the destination buffer size:No parsing behavior changes for well-formed SDP (real tokens are far shorter than the limits).
Verification
Compiled
tuya_sdp.cstandalone with stubs and exercisedtuya_p2p_rtc_sdp_decode()under AddressSanitizer with a malicious SDP containing 200-byte/300-byte tokens in all five affected lines:AddressSanitizer: stack-buffer-overflow, WRITE of 201 bytes intowms_id(char[65]) attuya_sdp.c:948— crashes exactly at the reported locationAlso confirmed the remaining
sscanfcalls insrc/tuya_p2p/are either numeric-only or already width-limited (%63sinlocal_store.c).