[Asterisk-code-review] res_stasis_playback: Prevent media_index from going out of bounds (asterisk[master])

Friendly Automation asteriskteam at digium.com
Wed Feb 5 10:39:30 CST 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13709 )

Change subject: res_stasis_playback: Prevent media_index from going out of bounds
......................................................................

res_stasis_playback: Prevent media_index from going out of bounds

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
---
M res/res_stasis_playback.c
1 file changed, 3 insertions(+), 1 deletion(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index 4a75382..7665d5f 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -287,6 +287,7 @@
 {
 	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
@@ -305,7 +306,8 @@
 
 	offsetms = playback->offsetms;
 
-	for (; playback->media_index < AST_VECTOR_SIZE(&playback->medias); playback->media_index++) {
+	for (index = 0; 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));

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13709
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ib53f7f156097e0607eb5871d9d78d246ed274928
Gerrit-Change-Number: 13709
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200205/4fae1423/attachment.html>


More information about the asterisk-code-review mailing list