@@ -1500,6 +1500,8 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
15001500 int minDepth;
15011501 /* Integer had a zero prepended. */
15021502 int zeroPadded;
1503+ word32 tmpW32Val;
1504+ signed char tmpScharVal;
15031505
15041506#ifdef WOLFSSL_DEBUG_ASN_TEMPLATE
15051507 WOLFSSL_ENTER("GetASN_Items");
@@ -1538,14 +1540,18 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
15381540 /* Check if first of numbered choice. */
15391541 if (choice == 0 && asn[i].optional > 1) {
15401542 choice = asn[i].optional;
1541- if (choiceMet[choice - 2] == -1) {
1543+ tmpScharVal = choiceMet[choice - 2];
1544+ XFENCE(); /* Prevent memory access */
1545+ if (tmpScharVal == -1) {
15421546 /* Choice seen but not found a match yet. */
15431547 choiceMet[choice - 2] = 0;
15441548 }
15451549 }
15461550
15471551 /* Check for end of data or not a choice and tag not matching. */
1548- if (idx == endIdx[depth] || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
1552+ tmpW32Val = endIdx[depth];
1553+ XFENCE(); /* Prevent memory access */
1554+ if (idx == tmpW32Val || (data[i].dataType != ASN_DATA_TYPE_CHOICE &&
15491555 (input[idx] & ~ASN_CONSTRUCTED) != asn[i].tag)) {
15501556 if (asn[i].optional) {
15511557 /* Skip over ASN.1 items underneath this optional item. */
@@ -1613,6 +1619,7 @@ int GetASN_Items(const ASNItem* asn, ASNGetData *data, int count, int complete,
16131619
16141620 /* Store found tag in data. */
16151621 data[i].tag = input[idx];
1622+ XFENCE(); /* Prevent memory access */
16161623 if (data[i].dataType != ASN_DATA_TYPE_CHOICE) {
16171624 int constructed = (input[idx] & ASN_CONSTRUCTED) == ASN_CONSTRUCTED;
16181625 /* Check constructed match expected for non-choice ASN.1 item. */
0 commit comments