FS-11965: RTC: prevent overflow on percent_fraction

(patch by Sergey Khripchenko <shripchenko@intermedia.net>)
This commit is contained in:
Dragos Oancea 2019-07-25 23:07:15 +00:00
parent 2e450cd3dc
commit 9e006869e4
1 changed files with 3 additions and 3 deletions

View 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);