diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index c67fd92c5..a237a1716 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1283,6 +1283,13 @@ static int GetASN_StoreData(const ASNItem* asn, ASNGetData* data, #endif return ASN_PARSE_E; } + if ((asn->tag != ASN_BOOLEAN) && (!zeroPadded) && + (input[idx] >= 0x80U)) { + #ifdef WOLFSSL_DEBUG_ASN_TEMPLATE + WOLFSSL_MSG_VSNPRINTF("Unexpected negative INTEGER value"); + #endif + return ASN_EXPECT_0_E; + } /* Fill number with all of data. */ *data->data.u8 = input[idx]; break;