]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11965: RTC: prevent overflow on percent_fraction
authorDragos Oancea <dragos@signalwire.com>
Thu, 25 Jul 2019 23:07:15 +0000 (23:07 +0000)
committerDragos Oancea <dragos@signalwire.com>
Thu, 25 Jul 2019 23:10:53 +0000 (23:10 +0000)
(patch by Sergey Khripchenko <shripchenko@intermedia.net>)

src/switch_rtp.c

index cd39093e7c67f6106703524ce3a574c33df31d2d..795f41207d46c2c024c61850cd7b0596d14baf68 100644 (file)
@@ -6716,12 +6716,12 @@ static switch_status_t process_rtcp_report(switch_rtp_t *rtp_session, rtcp_msg_t
 
                        for (i = 0; i < (int)msg->header.count && i < MAX_REPORT_BLOCKS ; i++) {
                                uint32_t old_avg = rtp_session->rtcp_frame.reports[i].loss_avg;
-                               uint8_t percent_fraction = (uint8_t)report->fraction * 100 / 256 ;
+                               uint8_t percent_fraction = (uint8_t)((uint16_t/* prevent overflow when '* 100' */)(uint8_t)report->fraction * 100 / 255);
                                if (!rtp_session->rtcp_frame.reports[i].loss_avg) {
-                                       rtp_session->rtcp_frame.reports[i].loss_avg = (uint8_t)percent_fraction;
+                                       rtp_session->rtcp_frame.reports[i].loss_avg = percent_fraction;
                                } else {
                                        rtp_session->rtcp_frame.reports[i].loss_avg = (uint32_t)(((float)rtp_session->rtcp_frame.reports[i].loss_avg * .7) +
-                                                                                                                                                        ((float)(uint8_t)percent_fraction * .3));
+                                                                                                                                                        ((float)percent_fraction * .3));
                                }
 
                                rtp_session->rtcp_frame.reports[i].ssrc = ntohl(report->ssrc);