From a08c0c7e5dc5126f71a17a12e12c4c0ea2d41aaf Mon Sep 17 00:00:00 2001 From: Alec L Davis <sivad.a@paradise.net.nz> Date: Thu, 2 May 2013 06:54:05 +0000 Subject: [PATCH] chan_dahdi: fix lower bound check with -ve integer conversion from a float Lower bound of a 16bit signed int is -32768 not -32767 (closes issue ASTERISK-21744) Reported by: alecdavis Tested by: alecdavis alecdavis (license 585) ........ Merged revisions 387297 from http://svn.asterisk.org/svn/asterisk/branches/1.8 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@387298 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_dahdi.c | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c index aeb15e014c..e52a3daaa4 100644 --- a/channels/chan_dahdi.c +++ b/channels/chan_dahdi.c @@ -5127,9 +5127,12 @@ static void fill_txgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->txgain[j] = AST_LIN2A(k); } else { g->txgain[j] = j; @@ -5143,9 +5146,12 @@ static void fill_txgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->txgain[j] = AST_LIN2MU(k); } else { @@ -5170,9 +5176,12 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->rxgain[j] = AST_LIN2A(k); } else { g->rxgain[j] = j; @@ -5186,9 +5195,12 @@ static void fill_rxgain(struct dahdi_gains *g, float gain, float drc, int law) if (drc) { k = drc_sample(k, drc); } - k = (float)k*linear_gain; - if (k > 32767) k = 32767; - if (k < -32767) k = -32767; + k = (float)k * linear_gain; + if (k > 32767) { + k = 32767; + } else if (k < -32768) { + k = -32768; + } g->rxgain[j] = AST_LIN2MU(k); } else { g->rxgain[j] = j; -- GitLab