Skip to content

Commit 1ada2e6

Browse files
additional sanity check with GetIntPositive
1 parent 70c362f commit 1ada2e6

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

wolfcrypt/src/asn.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3283,8 +3283,21 @@ static int GetIntPositive(mp_int* mpi, const byte* input, word32* inOutIdx,
32833283
if (ret != 0)
32843284
return ret;
32853285

3286-
if (((input[idx] & 0x80) == 0x80) && (input[idx - 1] != 0x00))
3286+
/* should not be hit but adding in an additional sanity check */
3287+
if (idx + length > maxIdx) {
32873288
return MP_INIT_E;
3289+
}
3290+
3291+
if ((input[idx] & 0x80) == 0x80) {
3292+
if (idx < 1) {
3293+
/* needs at least one byte for length value */
3294+
return MP_INIT_E;
3295+
}
3296+
3297+
if (input[idx - 1] != 0x00) {
3298+
return MP_INIT_E;
3299+
}
3300+
}
32883301

32893302
if (initNum) {
32903303
if (mp_init(mpi) != MP_OKAY)

0 commit comments

Comments
 (0)