Skip to content

Commit 58c41b6

Browse files
authored
Merge pull request #10458 from philljj/fix_GetShortInt
asn: fix GetShortInt for asn original.
2 parents cef3187 + 333aaaa commit 58c41b6

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

tests/api/test_asn.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,20 @@ int test_GetSetShortInt(void)
753753
ExpectIntEQ(GetShortInt(valDer, &idx, &value, 6),
754754
WC_NO_ERR_TRACE(ASN_EXPECT_0_E));
755755
}
756-
#endif
756+
757+
#if (!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)) || \
758+
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
759+
/* zero length value. should return ASN_PARSE_E */
760+
{
761+
word32 idx = 0;
762+
int value = 0;
763+
valDer[0] = ASN_INTEGER;
764+
valDer[1] = 0x00;
765+
ExpectIntEQ(GetShortInt(valDer, &idx, &value, 2),
766+
WC_NO_ERR_TRACE(ASN_PARSE_E));
767+
}
768+
#endif /* */
769+
#endif /* !NO_PWDBASED || WOLFSSL_ASN_EXTRA */
757770
#endif
758771

759772
return EXPECT_RESULT();

wolfcrypt/src/asn.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,13 @@ int GetShortInt(const byte* input, word32* inOutIdx, int* number, word32 maxIdx)
34653465
if (len > 4)
34663466
return ASN_PARSE_E;
34673467

3468+
/* to be consistent with GetASN_Integer */
3469+
#if (!defined(HAVE_SELFTEST) && !defined(HAVE_FIPS)) || \
3470+
(defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION > 2))
3471+
if (len == 0)
3472+
return ASN_PARSE_E;
3473+
#endif
3474+
34683475
if (len + idx > maxIdx)
34693476
return ASN_PARSE_E;
34703477

0 commit comments

Comments
 (0)