[pjsip] Divide by Zero Error

Jim Gomes Jim.Gomes at tideworks.com
Wed Feb 27 13:40:35 EST 2008


  

Hi Benny,

 

Here is a potential patch that will fix a divide by zero error.  There
are two ways of approaching this problem, and it's up to you how you
would like to approach it.  One way is to fix the initialization of
sd->ptime so that it is not set to zero.  The other is to check it every
time before it is used for division.  I went with the simpler approach
in this patch of checking at initialization time.  There are several
other areas where divide by zero errors can occur without proper
checking.  A thorough code review should be done to find them all.

 

Index: silencedet.c
===================================================================
--- silencedet.c  (revision 1823)
+++ silencedet.c  (working copy)
@@ -65,6 +65,7 @@
                                    pjmedia_silence_det **p_sd)
 {
     pjmedia_silence_det *sd;
+    unsigned frametime;
 
     PJ_ASSERT_RETURN(pool && p_sd, PJ_EINVAL);
 
@@ -73,7 +74,11 @@
     pj_ansi_strncpy(sd->objname, THIS_FILE, PJ_MAX_OBJ_NAME);
     sd->objname[PJ_MAX_OBJ_NAME-1] = '\0';
 
-    sd->ptime = samples_per_frame * 1000 / clock_rate;
+    /* Avoid divide by zero errors.  Max sure ptime is non-zero. */
+    frametime = samples_per_frame * 1000 / clock_rate;
+    if(frametime == 0)
+     frametime = 1;
+    sd->ptime = frametime;
     sd->signal_cnt = 0;
     sd->silence_cnt = 0;
     sd->weakest_signal = 0xFFFFFFFFUL;



 

Regards,

Jim Gomes

 

From: pjsip-bounces at lists.pjsip.org
[mailto:pjsip-bounces at lists.pjsip.org] On Behalf Of Jim Gomes
Sent: Friday, 22 February, 2008 4:24 PM
To: pjsip at pjsip.org
Subject: [pjsip] Divide by Zero Error

 

Benny,

The following code in the function pjmedia_silence_det_set_params(...)
gave a divide by zero error:

    sd->min_signal_cnt = min_signal / sd->ptime;

    sd->min_silence_cnt = min_silence / sd->ptime;

    sd->recalc_cnt = recalc_time / sd->ptime;

 

I was experiencing other errors, but this code should be protected
against error conditions and should check the value of sd->ptime for
zero before performing the division operation.

Regards,

Jim Gomes
Senior Software Engineer
Gate Technologies
Tideworks Technology, Inc.
(206) 382-2197

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20080227/37ca3ca4/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 2743 bytes
Desc: image001.jpg
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20080227/37ca3ca4/attachment.jpg>


More information about the pjsip mailing list