Skip to content

Commit 0014c75

Browse files
fix: bound sprop-parameter-sets copy to prevent SDP stack overflow
SessionDescriptor::generateFormatContext() copied the camera-controlled SDP sprop-parameter-sets value into a fixed char pvalue[1024] stack buffer with an unbounded strcpy(), so a malicious or MitM'd RTSP camera returning an oversized sprop-parameter-sets in its DESCRIBE response could overflow the stack (saved frame pointer / return address) for RCE as the capture process user. A real H.264 SPS/PPS base64 blob is small; refuse anything that would not fit the buffer instead of copying it. The existing inner base64 parse loop was already bounded, so only this outer copy was unsafe. Refs GHSA-wg5h-vcgv-74pv. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8030901 commit 0014c75

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/zm_sdp.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,17 @@ AVFormatContext *SessionDescriptor::generateFormatContext() const {
367367
codec_context->extradata= nullptr;
368368
char pvalue[1024], *value = pvalue;
369369

370-
strcpy(pvalue, mediaDesc->getSprops().c_str());
370+
// sprop-parameter-sets comes from the (untrusted) camera SDP. A real
371+
// H.264 SPS/PPS base64 blob is small; anything approaching the buffer
372+
// size is malformed or hostile, so refuse it rather than overflow the
373+
// stack with an unbounded strcpy.
374+
if (mediaDesc->getSprops().size() >= sizeof(pvalue)) {
375+
Warning("Ignoring oversized sprop-parameter-sets (%zu bytes) from SDP",
376+
mediaDesc->getSprops().size());
377+
pvalue[0] = '\0';
378+
} else {
379+
strcpy(pvalue, mediaDesc->getSprops().c_str());
380+
}
371381

372382
while ( *value ) {
373383
char base64packet[1024];

0 commit comments

Comments
 (0)