From af7e7c08f19b2f97c3aa3d4edeee0cbf0201cb7c Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Tue, 28 Jan 2020 14:23:19 -0500 Subject: [PATCH] res_stasis_playback: Prevent media_index from going out of bounds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Incrementing stasis_app_playback.media_index directly in our playback loop means that when we reach the end of our playlist the index into the vector will be outside of the bounds of the vector. Instead use a temporary variable and only assign when we're sure that we are in bounds. ASTERISK-28713 #close Reported by: Sébastien Duthil Change-Id: Ib53f7f156097e0607eb5871d9d78d246ed274928 --- res/res_stasis_playback.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c index 4a75382377..e275f04d9a 100644 --- a/res/res_stasis_playback.c +++ b/res/res_stasis_playback.c @@ -287,6 +287,7 @@ static void play_on_channel(struct stasis_app_playback *playback, { int res; long offsetms; + size_t index; /* Even though these local variables look fairly pointless, they avoid * having a bunch of NULL's passed directly into @@ -304,8 +305,10 @@ static void play_on_channel(struct stasis_app_playback *playback, } offsetms = playback->offsetms; + index = playback->media_index; - for (; playback->media_index < AST_VECTOR_SIZE(&playback->medias); playback->media_index++) { + for (; index < AST_VECTOR_SIZE(&playback->medias); index++) { + playback->media_index = index; /* Set the current media to play */ ast_string_field_set(playback, media, AST_VECTOR_GET(&playback->medias, playback->media_index)); -- 2.20.1