Skip to content

Commit d468139

Browse files
authored
Merge pull request #5892 from tatowicz/decodealtnames-fuzz-fix
Add Overflow check to DecodeAltNames input buffer access
2 parents a3f3c76 + 370e0ce commit d468139

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17338,6 +17338,7 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1733817338
#ifndef WOLFSSL_ASN_TEMPLATE
1733917339
word32 idx = 0;
1734017340
int length = 0;
17341+
byte current_byte;
1734117342

1734217343
WOLFSSL_ENTER("DecodeAltNames");
1734317344

@@ -17362,13 +17363,19 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1736217363
cert->weOwnAltNames = 1;
1736317364

1736417365
while (length > 0) {
17365-
byte b = input[idx++];
17366+
/* Verify idx can't overflow input buffer */
17367+
if (idx >= (word32)sz) {
17368+
WOLFSSL_MSG("\tBad Index");
17369+
return BUFFER_E;
17370+
}
17371+
17372+
current_byte = input[idx++];
1736617373

1736717374
length--;
1736817375

1736917376
/* Save DNS Type names in the altNames list. */
1737017377
/* Save Other Type names in the cert's OidMap */
17371-
if (b == (ASN_CONTEXT_SPECIFIC | ASN_DNS_TYPE)) {
17378+
if (current_byte == (ASN_CONTEXT_SPECIFIC | ASN_DNS_TYPE)) {
1737217379
DNS_entry* dnsEntry;
1737317380
int strLen;
1737417381
word32 lenStartIdx = idx;
@@ -17403,7 +17410,8 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1740317410
idx += strLen;
1740417411
}
1740517412
#ifndef IGNORE_NAME_CONSTRAINTS
17406-
else if (b == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | ASN_DIR_TYPE)) {
17413+
else if (current_byte ==
17414+
(ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | ASN_DIR_TYPE)) {
1740717415
DNS_entry* dirEntry;
1740817416
int strLen;
1740917417
word32 lenStartIdx = idx;
@@ -17442,7 +17450,7 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1744217450
length -= strLen;
1744317451
idx += strLen;
1744417452
}
17445-
else if (b == (ASN_CONTEXT_SPECIFIC | ASN_RFC822_TYPE)) {
17453+
else if (current_byte == (ASN_CONTEXT_SPECIFIC | ASN_RFC822_TYPE)) {
1744617454
DNS_entry* emailEntry;
1744717455
int strLen;
1744817456
word32 lenStartIdx = idx;
@@ -17477,7 +17485,7 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1747717485
length -= strLen;
1747817486
idx += strLen;
1747917487
}
17480-
else if (b == (ASN_CONTEXT_SPECIFIC | ASN_URI_TYPE)) {
17488+
else if (current_byte == (ASN_CONTEXT_SPECIFIC | ASN_URI_TYPE)) {
1748117489
DNS_entry* uriEntry;
1748217490
int strLen;
1748317491
word32 lenStartIdx = idx;
@@ -17548,7 +17556,7 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1754817556
idx += strLen;
1754917557
}
1755017558
#if defined(WOLFSSL_QT) || defined(OPENSSL_ALL) || defined(WOLFSSL_IP_ALT_NAME)
17551-
else if (b == (ASN_CONTEXT_SPECIFIC | ASN_IP_TYPE)) {
17559+
else if (current_byte == (ASN_CONTEXT_SPECIFIC | ASN_IP_TYPE)) {
1755217560
DNS_entry* ipAddr;
1755317561
int strLen;
1755417562
word32 lenStartIdx = idx;
@@ -17597,8 +17605,8 @@ static int DecodeAltNames(const byte* input, int sz, DecodedCert* cert)
1759717605
}
1759817606
#endif /* WOLFSSL_QT || OPENSSL_ALL */
1759917607
#endif /* IGNORE_NAME_CONSTRAINTS */
17600-
else if (b == (ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | ASN_OTHER_TYPE))
17601-
{
17608+
else if (current_byte ==
17609+
(ASN_CONTEXT_SPECIFIC | ASN_CONSTRUCTED | ASN_OTHER_TYPE)) {
1760217610
int strLen;
1760317611
word32 lenStartIdx = idx;
1760417612
word32 oid = 0;

0 commit comments

Comments
 (0)