]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
app_stream_echo.c: Check that stream is non-NULL before dereferencing.
authorSean Bright <sean@seanbright.com>
Mon, 1 Dec 2025 20:41:26 +0000 (15:41 -0500)
committergithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Wed, 3 Dec 2025 13:58:50 +0000 (13:58 +0000)
Also re-order and rename the arguments of `stream_echo_write_error` to
match those of `ast_write_stream` for consistency.

Resolves: #1427

apps/app_stream_echo.c

index abe3d9250e09df8213b26d6b1dd2dcc1ab1b45c1..8913f61cf101c4d90a22f0f77f9c76c2f820465d 100644 (file)
@@ -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);
                        }
                }
        }