From 9e006869e47bf60706da14c54f81c38ccaf790ca Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Thu, 25 Jul 2019 23:07:15 +0000 Subject: [PATCH] FS-11965: RTC: prevent overflow on percent_fraction (patch by Sergey Khripchenko ) --- src/switch_rtp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index cd39093e7c..795f41207d 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -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);