Rework to remove early function returns

This commit is contained in:
Josh Holtrop
2025-07-22 20:35:28 -04:00
parent 0d48911ae4
commit 2f2f999657

View File

@@ -2594,35 +2594,47 @@ int wc_IndexSequenceOf(const byte * seqOf, word32 seqOfSz, size_t seqIndex,
byte tagFound; byte tagFound;
size_t i; size_t i;
word32 elementIdx = 0U; word32 elementIdx = 0U;
int ret = 0;
/* Validate the SEQUENCE OF header. */ /* Validate the SEQUENCE OF header. */
if (GetSequence(seqOf, &seqOfIdx, &length, seqOfSz) < 0) if (GetSequence(seqOf, &seqOfIdx, &length, seqOfSz) < 0) {
return ASN_PARSE_E; ret = ASN_PARSE_E;
}
else {
seqOfSz = seqOfIdx + (word32)length; seqOfSz = seqOfIdx + (word32)length;
for (i = 0U; i <= seqIndex; i++) { for (i = 0U; i <= seqIndex; i++) {
if (seqOfIdx >= seqOfSz) if (seqOfIdx >= seqOfSz) {
return BAD_INDEX_E; ret = BAD_INDEX_E;
break;
}
elementIdx = seqOfIdx; elementIdx = seqOfIdx;
/* Validate the element tag. */ /* Validate the element tag. */
if (GetASNTag(seqOf, &seqOfIdx, &tagFound, seqOfSz) != 0) if (GetASNTag(seqOf, &seqOfIdx, &tagFound, seqOfSz) != 0) {
return ASN_PARSE_E; ret = ASN_PARSE_E;
break;
}
/* Validate and get the element's encoded length. */ /* Validate and get the element's encoded length. */
if (GetLength(seqOf, &seqOfIdx, &length, seqOfSz) < 0) if (GetLength(seqOf, &seqOfIdx, &length, seqOfSz) < 0) {
return ASN_PARSE_E; ret = ASN_PARSE_E;
break;
}
seqOfIdx += (word32)length; seqOfIdx += (word32)length;
} }
}
/* If the tag and length checks above passed then we've found the requested /* If the tag and length checks above passed then we've found the requested
* element and validated it fits within seqOfSz. */ * element and validated it fits within seqOfSz. */
if (ret == 0) {
*out = &seqOf[elementIdx]; *out = &seqOf[elementIdx];
*outSz = (seqOfIdx - elementIdx); *outSz = (seqOfIdx - elementIdx);
return 0; }
return ret;
} }
/* Decode the header of a BER/DER encoded SET. /* Decode the header of a BER/DER encoded SET.