Merge pull request #10458 from philljj/fix_GetShortInt

asn: fix GetShortInt for asn original.
This commit is contained in:
Sean Parkinson
2026-05-13 16:44:38 +10:00
committed by GitHub
2 changed files with 21 additions and 1 deletions
+14 -1
View File
@@ -753,7 +753,20 @@ int test_GetSetShortInt(void)
ExpectIntEQ(GetShortInt(valDer, &idx, &value, 6),
WC_NO_ERR_TRACE(ASN_EXPECT_0_E));
}
#endif
#if (!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)) || \
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
/* zero length value. should return ASN_PARSE_E */
{
word32 idx = 0;
int value = 0;
valDer[0] = ASN_INTEGER;
valDer[1] = 0x00;
ExpectIntEQ(GetShortInt(valDer, &idx, &value, 2),
WC_NO_ERR_TRACE(ASN_PARSE_E));
}
#endif /* */
#endif /* !NO_PWDBASED || WOLFSSL_ASN_EXTRA */
#endif
return EXPECT_RESULT();
+7
View File
@@ -3465,6 +3465,13 @@ int GetShortInt(const byte* input, word32* inOutIdx, int* number, word32 maxIdx)
if (len > 4)
return ASN_PARSE_E;
/* to be consistent with GetASN_Integer */
#if (!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)) || \
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
if (len == 0)
return ASN_PARSE_E;
#endif
if (len + idx > maxIdx)
return ASN_PARSE_E;