Skip to content

Commit 5b83257

Browse files
committed
Add checks for ascii digits in time decode functions
1 parent 353a379 commit 5b83257

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

src/ssl_asn1.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,14 @@ static int wolfssl_utctime_year(const unsigned char* str, int len, int* year)
42934293
ret = 0;
42944294
}
42954295

4296+
if (ret == 1) {
4297+
if ((str[0] < '0') || (str[0] > '9') ||
4298+
(str[1] < '0') || (str[1] > '9')) {
4299+
WOLFSSL_MSG("Invalid characters in UTC year.");
4300+
ret = 0;
4301+
}
4302+
}
4303+
42964304
if (ret == 1) {
42974305
int tm_year;
42984306
/* 2-digit year. */
@@ -4334,6 +4342,16 @@ static int wolfssl_gentime_year(const unsigned char* str, int len, int* year)
43344342
ret = 0;
43354343
}
43364344

4345+
if (ret == 1) {
4346+
if ((str[0] < '0') || (str[0] > '9') ||
4347+
(str[1] < '0') || (str[1] > '9') ||
4348+
(str[2] < '0') || (str[2] > '9') ||
4349+
(str[3] < '0') || (str[3] > '9')) {
4350+
WOLFSSL_MSG("Invalid characters in generalized year.");
4351+
ret = 0;
4352+
}
4353+
}
4354+
43374355
if (ret == 1) {
43384356
int tm_year;
43394357
/* 4-digit year. */
@@ -4406,8 +4424,22 @@ static int wolfssl_asn1_time_to_tm(const WOLFSSL_ASN1_TIME* asnTime,
44064424
WOLFSSL_MSG("asnTime->type is invalid.");
44074425
ret = 0;
44084426
}
4409-
}
4410-
if (ret == 1) {
4427+
}
4428+
4429+
if (ret == 1) {
4430+
int j;
4431+
/* Validate 10 digits: MMDDHHMMSS. Length was already checked
4432+
* (>= UTCTIME_LEN or >= GENTIME_LEN), so i+10 is in range. */
4433+
for (j = i; j < i + 10; j++) {
4434+
if (asn1TimeBuf[j] < '0' || asn1TimeBuf[j] > '9') {
4435+
WOLFSSL_MSG("Non-digit in ASN.1 TIME.");
4436+
ret = 0;
4437+
break;
4438+
}
4439+
}
4440+
}
4441+
4442+
if (ret == 1) {
44114443
/* Fill in rest of broken-down time from string. */
44124444
/* January is 0 not 1 */
44134445
tm->tm_mon = (asn1TimeBuf[i] - '0') * 10; i++;

0 commit comments

Comments
 (0)