From 1ada2e6a4360d1ed5ad74646801fc4b5b3d70079 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Tue, 29 Aug 2023 15:43:01 -0700 Subject: [PATCH] additional sanity check with GetIntPositive --- wolfcrypt/src/asn.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 08af5b48c..483a659f2 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -3283,8 +3283,21 @@ static int GetIntPositive(mp_int* mpi, const byte* input, word32* inOutIdx, if (ret != 0) return ret; - if (((input[idx] & 0x80) == 0x80) && (input[idx - 1] != 0x00)) + /* should not be hit but adding in an additional sanity check */ + if (idx + length > maxIdx) { return MP_INIT_E; + } + + if ((input[idx] & 0x80) == 0x80) { + if (idx < 1) { + /* needs at least one byte for length value */ + return MP_INIT_E; + } + + if (input[idx - 1] != 0x00) { + return MP_INIT_E; + } + } if (initNum) { if (mp_init(mpi) != MP_OKAY)