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

Friendly Automation asteriskteam at digium.com
Mon Mar 11 09:45:28 CDT 2019


Friendly Automation has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11085 )

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
  mattf: Looks good to me, but someone else must approve
  Sean Bright: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 84b2088..6a5fb0a 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -3075,6 +3075,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;
 }
 
@@ -3091,6 +3099,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/+/11085
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: If7e0629abaceddd2166eb012456c53033ea26249
Gerrit-Change-Number: 11085
Gerrit-PatchSet: 5
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
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-Reviewer: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190311/46c021ff/attachment-0001.html>


More information about the asterisk-code-review mailing list