aboutsummaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authortlatorre <tlatorre@uchicago.edu>2018-09-18 18:04:52 -0500
committertlatorre <tlatorre@uchicago.edu>2018-09-18 18:04:52 -0500
commit5938f05b8fc5feef6f823a51c977b4f0cf51050f (patch)
tree73c0ba3eefa5ad3cd8843f9551a5cb25c1f72656 /src/misc.c
parentf865d2303b4ac82dca2680626ae94c26efe63450 (diff)
downloadsddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.tar.gz
sddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.tar.bz2
sddm-5938f05b8fc5feef6f823a51c977b4f0cf51050f.zip
fix heap overflow in interp1d()
This commit fixes a potential heap overflow in interp1d() which could occur if x was very close to the last value in the xp array. The bounds check is now performed on the index rather than the x values.
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 00f2f6c..189d49b 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -327,10 +327,11 @@ double interp1d(double x, double *xp, double *yp, size_t n)
size_t i;
if (x <= xp[0]) return yp[0];
- if (x >= xp[n-1]) return yp[n-1];
i = (x-xp[0])/(xp[1]-xp[0]);
+ if (i > n-2) return yp[n-1];
+
return yp[i] + (yp[i+1]-yp[i])*(x-xp[i])/(xp[i+1]-xp[i]);
}