@@ -2406,21 +2406,12 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx,
24062406 }
24072407
24082408 /*
2409- * verify that stream is for received traffic - this check will
2410- * detect SSRC collisions, since a stream that appears in both
2411- * srtp_protect() and srtp_unprotect() will fail this test in one of
2412- * those functions.
2413- *
24142409 * we do this check *after* the authentication check, so that the
24152410 * latter check will catch any attempts to fool us into thinking
24162411 * that we've got a collision
24172412 */
2418- if (stream -> direction != dir_srtp_receiver ) {
2419- if (stream -> direction == dir_unknown ) {
2420- stream -> direction = dir_srtp_receiver ;
2421- } else {
2422- srtp_handle_event (ctx , stream , event_ssrc_collision );
2423- }
2413+ if (stream -> direction == dir_unknown ) {
2414+ stream -> direction = dir_srtp_receiver ;
24242415 }
24252416
24262417 /*
@@ -2560,6 +2551,7 @@ srtp_err_status_t srtp_protect(srtp_t ctx,
25602551 stream -> direction = dir_srtp_sender ;
25612552 } else {
25622553 srtp_handle_event (ctx , stream , event_ssrc_collision );
2554+ return srtp_err_status_direction_mismatch ;
25632555 }
25642556 }
25652557
@@ -2873,6 +2865,18 @@ srtp_err_status_t srtp_unprotect(srtp_t ctx,
28732865 return srtp_err_status_no_ctx ;
28742866 }
28752867 } else {
2868+ /*
2869+ * Verify that stream is for received traffic - this check will
2870+ * detect SSRC collisions, since a stream that appears in both
2871+ * srtp_protect() and srtp_unprotect() will fail this test in one of
2872+ * those functions.
2873+ *
2874+ */
2875+ if (stream -> direction == dir_srtp_sender ) {
2876+ srtp_handle_event (ctx , stream , event_ssrc_collision );
2877+ return srtp_err_status_direction_mismatch ;
2878+ }
2879+
28762880 status = srtp_get_est_pkt_index (hdr , stream , & est , & delta );
28772881
28782882 if (status && (status != srtp_err_status_pkt_idx_adv )) {
@@ -3098,21 +3102,12 @@ srtp_err_status_t srtp_unprotect(srtp_t ctx,
30983102 }
30993103
31003104 /*
3101- * verify that stream is for received traffic - this check will
3102- * detect SSRC collisions, since a stream that appears in both
3103- * srtp_protect() and srtp_unprotect() will fail this test in one of
3104- * those functions.
3105- *
31063105 * we do this check *after* the authentication check, so that the
31073106 * latter check will catch any attempts to fool us into thinking
31083107 * that we've got a collision
31093108 */
3110- if (stream -> direction != dir_srtp_receiver ) {
3111- if (stream -> direction == dir_unknown ) {
3112- stream -> direction = dir_srtp_receiver ;
3113- } else {
3114- srtp_handle_event (ctx , stream , event_ssrc_collision );
3115- }
3109+ if (stream -> direction == dir_unknown ) {
3110+ stream -> direction = dir_srtp_receiver ;
31163111 }
31173112
31183113 /*
@@ -4009,21 +4004,12 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead(
40094004 * rtcp_len -= (tag_len + sizeof (srtcp_trailer_t ) + stream -> mki_size );
40104005
40114006 /*
4012- * verify that stream is for received traffic - this check will
4013- * detect SSRC collisions, since a stream that appears in both
4014- * srtp_protect() and srtp_unprotect() will fail this test in one of
4015- * those functions.
4016- *
40174007 * we do this check *after* the authentication check, so that the
40184008 * latter check will catch any attempts to fool us into thinking
40194009 * that we've got a collision
40204010 */
4021- if (stream -> direction != dir_srtp_receiver ) {
4022- if (stream -> direction == dir_unknown ) {
4023- stream -> direction = dir_srtp_receiver ;
4024- } else {
4025- srtp_handle_event (ctx , stream , event_ssrc_collision );
4026- }
4011+ if (stream -> direction == dir_unknown ) {
4012+ stream -> direction = dir_srtp_receiver ;
40274013 }
40284014
40294015 /*
@@ -4139,6 +4125,7 @@ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
41394125 stream -> direction = dir_srtp_sender ;
41404126 } else {
41414127 srtp_handle_event (ctx , stream , event_ssrc_collision );
4128+ return srtp_err_status_direction_mismatch ;
41424129 }
41434130 }
41444131
@@ -4368,6 +4355,17 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
43684355 }
43694356 }
43704357
4358+ /*
4359+ * verify that stream is for received traffic - this check will
4360+ * detect SSRC collisions, since a stream that appears in both
4361+ * srtp_protect() and srtp_unprotect() will fail this test in one of
4362+ * those functions.
4363+ */
4364+ if (stream -> direction == dir_srtp_sender ) {
4365+ srtp_handle_event (ctx , stream , event_ssrc_collision );
4366+ return srtp_err_status_direction_mismatch ;
4367+ }
4368+
43714369 /*
43724370 * Determine if MKI is being used and what session keys should be used
43734371 */
@@ -4547,21 +4545,12 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
45474545 * rtcp_len -= stream -> mki_size ;
45484546
45494547 /*
4550- * verify that stream is for received traffic - this check will
4551- * detect SSRC collisions, since a stream that appears in both
4552- * srtp_protect() and srtp_unprotect() will fail this test in one of
4553- * those functions.
4554- *
45554548 * we do this check *after* the authentication check, so that the
45564549 * latter check will catch any attempts to fool us into thinking
45574550 * that we've got a collision
45584551 */
4559- if (stream -> direction != dir_srtp_receiver ) {
4560- if (stream -> direction == dir_unknown ) {
4561- stream -> direction = dir_srtp_receiver ;
4562- } else {
4563- srtp_handle_event (ctx , stream , event_ssrc_collision );
4564- }
4552+ if (stream -> direction == dir_unknown ) {
4553+ stream -> direction = dir_srtp_receiver ;
45654554 }
45664555
45674556 /*
0 commit comments