From a969ebaee9bf5649f9366b8ada2a5b5087bee872 Mon Sep 17 00:00:00 2001
From: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
Date: Fri, 12 Jul 2013 15:02:27 -0400
Subject: [PATCH]  * #27201: libiax: avoid out of bounds read in a more obvious
 way

---
 daemon/libs/iax2/jitterbuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/daemon/libs/iax2/jitterbuf.c b/daemon/libs/iax2/jitterbuf.c
index 135c5d4d27..6e74c3fc40 100644
--- a/daemon/libs/iax2/jitterbuf.c
+++ b/daemon/libs/iax2/jitterbuf.c
@@ -239,7 +239,7 @@ static void history_calc_maxbuf(jitterbuf *jb)
 				if (toins > jb->hist_maxbuf[j]) {
 					/* move over if there's space */
                     const size_t slide = (JB_HISTORY_MAXBUF_SZ - (j + 1)) * sizeof(jb->hist_maxbuf[0]);
-					if (slide > 0)
+					if (j < (JB_HISTORY_MAXBUF_SZ - 1))
 						memmove(jb->hist_maxbuf + j + 1, jb->hist_maxbuf + j, slide);
 					/* insert */
 					jb->hist_maxbuf[j] = toins;
@@ -258,7 +258,7 @@ static void history_calc_maxbuf(jitterbuf *jb)
 				if (toins < jb->hist_minbuf[j]) {
 					/* move over if there's space */
 					const size_t slide = (JB_HISTORY_MAXBUF_SZ - (j + 1)) * sizeof(jb->hist_minbuf[0]);
-					if (slide > 0)
+					if (j < (JB_HISTORY_MAXBUF_SZ - 1))
 						memmove(jb->hist_minbuf + j + 1, jb->hist_minbuf + j, slide);
 					/* insert */
 					jb->hist_minbuf[j] = toins;
-- 
GitLab