From: George Joseph Date: Thu, 23 Jul 2020 19:47:25 +0000 (-0600) Subject: res_pjsip_session: Ensure reused streams have correct bundle group X-Git-Tag: 17.7.0-rc1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5042ebf4ff4d7600f6f80365c23ecba168a615b6;p=thirdparty%2Fasterisk.git res_pjsip_session: Ensure reused streams have correct bundle group When a bundled stream is removed, its bundle_group is reset to -1. If that stream is later reused, the bundle parameters on session media need to be reset correctly it could mistakenly be rebundled with a stream that was removed and never reused. Since the removed stream has no rtp instance, a crash will result. Change-Id: Ie2b792220f9291587ab5f9fd123145559dba96d7 --- diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c index 980a1e99d1..9ad5577c3c 100644 --- a/res/res_pjsip_session.c +++ b/res/res_pjsip_session.c @@ -487,6 +487,20 @@ struct ast_sip_session_media *ast_sip_session_media_state_add(struct ast_sip_ses /* A stream can never exist without an accompanying media session */ if (session_media->type == type) { ao2_ref(session_media, +1); + /* + * If this session_media was previously removed, its bundle group was probably reset + * to -1 so if bundling is enabled on the endpoint, we need to reset it to 0, set + * the bundled flag and reset its mid. + */ + if (session->endpoint->media.bundle && session_media->bundle_group == -1) { + session_media->bundled = session->endpoint->media.webrtc; + session_media->bundle_group = 0; + ast_free(session_media->mid); + if (ast_asprintf(&session_media->mid, "%s-%d", ast_codec_media_type2str(type), position) < 0) { + ao2_ref(session_media, -1); + return NULL; + } + } } else { session_media = NULL; }