Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/api/test_asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Comment thread
philljj marked this conversation as resolved.
#endif

return EXPECT_RESULT();
Expand Down
7 changes: 7 additions & 0 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading