Skip to content

Commit 425eb7f

Browse files
committed
Stop assuming dates are NULL terminated
1 parent 67d2abf commit 425eb7f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

wolfcrypt/src/asn.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15030,18 +15030,18 @@ int ExtractDate(const unsigned char* date, unsigned char format,
1503015030
{
1503115031
int i = *idx;
1503215032

15033-
/* Validate date string length based on format */
15033+
/* Validate date string length based on format Can not assume null
15034+
* terminated strings. Must check for the 'Z'. Subtract 2; one for zero
15035+
* indexing and one to exclude null terminator built into macro values */
1503415036
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)) {
15037+
/* UTCTime format requires YYMMDDHHMMSSZ. */
15038+
if (date[i + ASN_UTC_TIME_SIZE - 2] != 'Z') {
1503815039
return ASN_PARSE_E;
1503915040
}
1504015041
}
1504115042
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)) {
15043+
/* GeneralizedTime format requires YYYYMMDDHHMMSSZ. */
15044+
if (date[ i + ASN_GENERALIZED_TIME_SIZE - 2] != 'Z') {
1504515045
return ASN_PARSE_E;
1504615046
}
1504715047
} else {

0 commit comments

Comments
 (0)