Skip to content

Commit b10ea03

Browse files
committed
rtp_engine.c: Prevent segfault in ast_rtp_codecs_payloads_unset()
There can be empty slots in payload_mapping_tx corresponding to dynamic payload types that haven't been seen before so we now check for NULL before attempting to use 'type' in the call to ast_format_cmp. Note: Currently only chan_sip calls ast_rtp_codecs_payloads_unset() Resolves: #822
1 parent 2fb3215 commit b10ea03

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

main/rtp_engine.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,12 +1485,21 @@ void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp
14851485

14861486
if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
14871487
type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1488-
/* remove the preferred format if we are unsetting its container. */
1489-
if (ast_format_cmp(type->format, codecs->preferred_format) == AST_FORMAT_CMP_EQUAL) {
1490-
ao2_replace(codecs->preferred_format, NULL);
1488+
/*
1489+
* Remove the preferred format if we are unsetting its container.
1490+
*
1491+
* There can be empty slots in payload_mapping_tx corresponding to
1492+
* dynamic payload types that haven't been seen before so we need
1493+
* to check for NULL before attempting to use 'type' in the call to
1494+
* ast_format_cmp.
1495+
*/
1496+
if (type) {
1497+
if (ast_format_cmp(type->format, codecs->preferred_format) == AST_FORMAT_CMP_EQUAL) {
1498+
ao2_replace(codecs->preferred_format, NULL);
1499+
}
1500+
ao2_ref(type, -1);
1501+
AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, NULL);
14911502
}
1492-
ao2_cleanup(type);
1493-
AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, NULL);
14941503
}
14951504

14961505
if (instance && instance->engine && instance->engine->payload_set) {

0 commit comments

Comments
 (0)