Commit 9647a4f022 for asterisk.org
commit 9647a4f022da560b3a66339e7583d239d4afd062
Author: Sean Bright <sean@seanbright.com>
Date: Mon Dec 1 15:41:26 2025 -0500
app_stream_echo.c: Check that stream is non-NULL before dereferencing.
Also re-order and rename the arguments of `stream_echo_write_error` to
match those of `ast_write_stream` for consistency.
Resolves: #1427
diff --git a/apps/app_stream_echo.c b/apps/app_stream_echo.c
index abe3d9250e..8913f61cf1 100644
--- a/apps/app_stream_echo.c
+++ b/apps/app_stream_echo.c
@@ -78,7 +78,7 @@
static const char app[] = "StreamEcho";
-static int stream_echo_write_error(struct ast_channel *chan, struct ast_frame *frame, int pos)
+static int stream_echo_write_error(struct ast_channel *chan, int stream_num, struct ast_frame *frame)
{
char frame_type[32];
const char *media_type;
@@ -86,9 +86,13 @@ static int stream_echo_write_error(struct ast_channel *chan, struct ast_frame *f
ast_frame_type2str(frame->frametype, frame_type, sizeof(frame_type));
- stream = pos < 0 ?
+ stream = stream_num < 0 ?
ast_channel_get_default_stream(chan, ast_format_get_type(frame->subclass.format)) :
- ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), pos);
+ ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), stream_num);
+
+ if (!stream) {
+ return -1;
+ }
media_type = ast_codec_media_type2str(ast_stream_get_type(stream));
@@ -112,7 +116,7 @@ static int stream_echo_write(struct ast_channel *chan, struct ast_frame *frame,
*/
num = ast_channel_is_multistream(chan) ? frame->stream_num : -1;
if (ast_write_stream(chan, num, frame)) {
- return stream_echo_write_error(chan, frame, num);
+ return stream_echo_write_error(chan, num, frame);
}
/*
@@ -146,7 +150,7 @@ static int stream_echo_write(struct ast_channel *chan, struct ast_frame *frame,
struct ast_stream *stream = ast_stream_topology_get_stream(topology, i);
if (num != i && ast_stream_get_type(stream) == type) {
if (ast_write_stream(chan, i, frame)) {
- return stream_echo_write_error(chan, frame, i);
+ return stream_echo_write_error(chan, i, frame);
}
}
}