From 38867ae2bf5b1fcdfb17bdcc7f2337e61935d6a6 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 12 Nov 2020 10:15:55 -0800 Subject: [PATCH] Scan-Build Fixes 1. Added a check to see if the "d" in sp_div() ended up with a negative used length. Return error if so. To recreate: $ scan-build ./configure --enable-sp --enable-sp-asm --enable-sp-math --- wolfcrypt/src/sp_int.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 9f9012cb0..ab1bd6dcc 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -927,6 +927,9 @@ static int sp_div(sp_int* a, sp_int* d, sp_int* r, sp_int* rem) d = sd; } + if (d->used < 0) + err = MP_VAL; + tr->used = sa->used - d->used + 1; sp_clear(tr); tr->used = sa->used - d->used + 1;