Skip to content

Fix buffer overflow and length-truncation bugs in RTP SDES packet builder#810

Open
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-rtpacket-sdes-sprintf
Open

Fix buffer overflow and length-truncation bugs in RTP SDES packet builder#810
MarkRose wants to merge 1 commit into
sm0svx:masterfrom
MarkRose:fix-rtpacket-sdes-sprintf

Conversation

@MarkRose

Copy link
Copy Markdown
Contributor
  • rtp_make_sdes() used sprintf(tmp, "%-15s%s", callsign, name) into a
    fixed 256-byte stack buffer with no bounds checking. A configured
    station name or callsign longer than roughly 240 bytes overflows the
    buffer. Switched to snprintf(tmp, sizeof(tmp), ...) to bound the write
    to the buffer size.

  • The addText() macro stored the text length in a single byte
    (*block++ = sl) but then memcpy'd the full, untruncated length (sl)
    into the output buffer. For any string longer than 255 bytes, the
    on-wire length field would wrap/truncate while memcpy still copied
    the full length, corrupting the packet layout and writing past the
    intended bounds of the SDES buffer. The macro now clamps the length
    to 255 before both recording it and copying it, so the copied data
    always matches the recorded length.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com


This PR also adds a unit test (RtPacketTest.cpp). It is auto-discovered and executed by the CTest suite proposed in #762 once that is merged; without that suite present the test file is inert and does not affect the build.

…lder

- rtp_make_sdes() used sprintf(tmp, "%-15s%s", callsign, name) into a
  fixed 256-byte stack buffer with no bounds checking. A configured
  station name or callsign longer than roughly 240 bytes overflows the
  buffer. Switched to snprintf(tmp, sizeof(tmp), ...) to bound the write
  to the buffer size.

- The addText() macro stored the text length in a single byte
  (*block++ = sl) but then memcpy'd the full, untruncated length (sl)
  into the output buffer. For any string longer than 255 bytes, the
  on-wire length field would wrap/truncate while memcpy still copied
  the full length, corrupting the packet layout and writing past the
  intended bounds of the SDES buffer. The macro now clamps the length
  to 255 before both recording it and copying it, so the copied data
  always matches the recorded length.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MarkRose
MarkRose force-pushed the fix-rtpacket-sdes-sprintf branch from 6dca554 to e12788b Compare July 11, 2026 23:07
@MarkRose MarkRose closed this Jul 12, 2026
@MarkRose MarkRose reopened this Jul 12, 2026
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.

1 participant