From 8761407cad39cd92a86a824246df02b743700d4a Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 17 Dec 2019 20:41:57 +0100 Subject: [PATCH] fix: cayleyTransform memory addressing problem due to int/double pointer cast. --- CVE/src/matrix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CVE/src/matrix.c b/CVE/src/matrix.c index 5bb39ad..cd490cd 100644 --- a/CVE/src/matrix.c +++ b/CVE/src/matrix.c @@ -942,11 +942,16 @@ mat* cayleyTransform(mat *A, mat *B, mat *C, double *workMem) { /* Allocate row permutation array used by `dgesv` */ int *ipiv = (int*)workMem; + /* NOTE: workMem offset, NOT ipiv offset! There may be a bit space left out + * but the working memory is required elsewhere anyway. It's impotant to + * have an appropriate beginning cause if may occure the case that the + * memory addressing faily due to size differences between int and double + * leading to an illegal double* address. */ + double *IpA = workMem + A->nrow; /* Create Matrix IpA = I + A (I plus A) */ - double *IpA = (double*)(ipiv + A->nrow); memcpy(IpA, A->elem, A->nrow * A->ncol * sizeof(double)); for (i = 0; i < pp; i += A->nrow + 1) { - IpA[i] += 1.; // +1 to diagonal elements. + IpA[i] += 1.0; // +1 to diagonal elements. } /* Create Matrix ImA = I - A (I minus A) */