Skip to content

Commit 67d2abf

Browse files
committed
Validate asn date based on string length
1 parent 1c56a26 commit 67d2abf

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

wolfcrypt/src/asn.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15028,6 +15028,26 @@ static WC_INLINE int GetTime_Long(long* value, const byte* date, int* idx)
1502815028
int ExtractDate(const unsigned char* date, unsigned char format,
1502915029
struct tm* certTime, int* idx)
1503015030
{
15031+
int i = *idx;
15032+
15033+
/* Validate date string length based on format */
15034+
if (format == ASN_UTC_TIME) {
15035+
/* UTCTime format requires YYMMDDHHMMSSZ.
15036+
* subtract 1 to exclude null terminator. */
15037+
if (XSTRLEN((const char*)date + i) < (ASN_UTC_TIME_SIZE - 1)) {
15038+
return ASN_PARSE_E;
15039+
}
15040+
}
15041+
else if (format == ASN_GENERALIZED_TIME) {
15042+
/* GeneralizedTime format requires YYYYMMDDHHMMSSZ.
15043+
* subtract 1 to exclude null terminator. */
15044+
if (XSTRLEN((const char*)date + i) < (ASN_GENERALIZED_TIME_SIZE - 1)) {
15045+
return ASN_PARSE_E;
15046+
}
15047+
} else {
15048+
return ASN_PARSE_E;
15049+
}
15050+
1503115051
XMEMSET(certTime, 0, sizeof(struct tm));
1503215052

1503315053
/* Get the first two bytes of the year (century) */

0 commit comments

Comments
 (0)