[Asterisk-code-review] res/res_rtp_asterisk.c: Fixing possible divide by zero (...asterisk[13])

Joshua C. Colp asteriskteam at digium.com
Wed Mar 13 05:37:05 CDT 2019


Joshua C. Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11123 )

Change subject: res/res_rtp_asterisk.c: Fixing possible divide by zero
......................................................................

res/res_rtp_asterisk.c: Fixing possible divide by zero

Currently, when the Asterisk calculates rtp statistics, it uses
sample_count as a unsigned integer parameter. This would be fine
for most of cases, but in case of large enough number of sample_count,
this might be causing the divide by zero error.

ASTERISK-28321

Change-Id: If7e0629abaceddd2166eb012456c53033ea26249
---
M res/res_rtp_asterisk.c
1 file changed, 16 insertions(+), 0 deletions(-)

Approvals:
  Joshua C. Colp: Looks good to me, but someone else must approve; Approved for Submit
  mattf: Looks good to me, but someone else must approve
  Sean Bright: Looks good to me, approved



diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index c5d557e..909d82a 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -2755,6 +2755,14 @@
 	normdev = normdev * sample_count + sample;
 	sample_count++;
 
+	/*
+	 It's possible the sample_count hits the maximum value and back to 0.
+	 Set to 1 to prevent the divide by zero crash if the sample_count is 0.
+	 */
+	if (sample_count == 0) {
+		sample_count = 1;
+	}
+
 	return normdev / sample_count;
 }
 
@@ -2771,6 +2779,14 @@
 	stddev = sample_count * stddev;
 	sample_count++;
 
+	/*
+	 It's possible the sample_count hits the maximum value and back to 0.
+	 Set to 1 to prevent the divide by zero crash if the sample_count is 0.
+	 */
+	if (sample_count == 0) {
+		sample_count = 1;
+	}
+
 	return stddev +
 		( sample_count * SQUARE( (sample - normdev) / sample_count ) ) +
 		( SQUARE(sample - normdev_curent) / sample_count );

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11123
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: If7e0629abaceddd2166eb012456c53033ea26249
Gerrit-Change-Number: 11123
Gerrit-PatchSet: 2
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua C. Colp <jcolp at digium.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: mattf <creslin at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190313/c6fae025/attachment.html>


More information about the asterisk-code-review mailing list