Skip to content

Clamp the notification length to the buffer in rtpp_catch_dtmf_worker - #205

Open
arfa-21 wants to merge 2 commits into
sippy:masterfrom
arfa-21:dtmf-notify-len-clamp
Open

arfa-21 wants to merge 2 commits into
sippy:masterfrom
arfa-21:dtmf-notify-len-clamp

Conversation

@arfa-21

@arfa-21 arfa-21 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Repro: run with -n tcp:127.0.0.1:<nport> and the catch_dtmf module, send U <cid> 127.0.0.1 <rport> ftag tcp:127.0.0.1:<nport> dtag && M3:1 <600-byte tag> 101 followed by an L, then send a telephone-event start/end pair (same RTP ts, end bit set on the second) to the port the U returned.

Cause: the worker sets notify_tag.len from snprintf()'s return value, which is the length the notification would have needed rather than the length that fit in the 512-byte buf. A command argument can be most of the 8 kB command buffer, so rtpp_notify_schedule() memcpy()s past buf and do_notification() sends the bytes that followed it on the module thread's stack to the notification target.

Fix: clamp the length to the buffer before building the string that gets handed on.

Built with -fsanitize=address, before the change:

ERROR: AddressSanitizer: stack-buffer-overflow
READ of size 611 at 0x7ffff039c280 thread T9
    #1 in memcpy /usr/include/x86_64-linux-gnu/bits/string_fortified.h:29
    #2 in rtpp_notify_schedule /work/src/rtpp_notify.c:193
    #3 in rtpp_catch_dtmf_worker /work/modules/catch_dtmf/rtpp_catch_dtmf.c:254

Address 0x7ffff039c280 is located in stack of thread T9 at offset 640 in frame
    #0 in rtpp_catch_dtmf_worker /work/modules/catch_dtmf/rtpp_catch_dtmf.c:180
  This frame has 3 object(s):
    [32, 48) 'notify_tag' (line 250)
    [64, 82) 'dtmf_events' (line 185)
    [128, 640) 'buf' (line 184) <== Memory access at offset 640 overflows this variable

After it the same run delivers a 511-byte notification with no report, a short tag comes out byte for byte as before, and tests/catch_dtmf/basic passes unchanged.

The DTMF worker formats the notification into a 512-byte stack buffer
with snprintf() and then uses snprintf()'s return value as
notify_tag.len. That value is the length the string would have needed,
not the length that fit. The tag is an argument of the M subcommand of
a U or L command, and command arguments are substrings of the 8 kB
command buffer with no length cap of their own, so for a tag of around
500 bytes or more rtpp_notify_schedule() memcpy()s past buf and
do_notification() sends whatever followed it on the module thread's
stack to the notification target.

Clamp the length to the buffer, so an over-long tag is truncated
instead of being read past.
@sobomax
sobomax force-pushed the dtmf-notify-len-clamp branch from 3aa38a0 to 43b1c82 Compare November 30, 2026 22:33
After the final statistics are taken, run an extra session per mode on the
same daemons, recorder and notification client, with a 512-byte callee tag.
The existing replay and its notification checks are unchanged. Each mode must
deliver six exact 511-byte notifications.
@sobomax
sobomax force-pushed the dtmf-notify-len-clamp branch from 43b1c82 to 96f3582 Compare November 30, 2026 22:41
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.

2 participants