Fix bug in wolfSSL_ASN1_TIME_diff.

This function should not error out if one of the passed in times is the Unix
epoch. This amounts to erroring out when the XMKTIME returns < 0, rather than
<= 0.
This commit is contained in:
Hayden Roche
2022-03-15 10:50:23 -07:00
parent d531e21f34
commit 6e6aa5b0c1
2 changed files with 13 additions and 5 deletions

View File

@ -32084,7 +32084,7 @@ int wolfSSL_ASN1_TIME_diff(int *days, int *secs, const WOLFSSL_ASN1_TIME *from,
}
fromSecs = XMKTIME(fromTm);
if (fromSecs <= 0) {
if (fromSecs < 0) {
WOLFSSL_MSG("XMKTIME for from time failed.");
return WOLFSSL_FAILURE;
}
@ -32103,7 +32103,7 @@ int wolfSSL_ASN1_TIME_diff(int *days, int *secs, const WOLFSSL_ASN1_TIME *from,
}
toSecs = XMKTIME(toTm);
if (toSecs <= 0) {
if (toSecs < 0) {
WOLFSSL_MSG("XMKTIME for to time failed.");
return WOLFSSL_FAILURE;
}

View File

@ -30618,15 +30618,23 @@ static void test_wolfSSL_ASN1_TIME_diff(void)
AssertNotNull((fromTime = ASN1_TIME_new()));
/* Feb 22, 2003, 21:15:15 */
AssertIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), 1);
AssertIntEQ(ASN1_TIME_set_string(fromTime, "030222211515Z"), WOLFSSL_SUCCESS);
AssertNotNull((toTime = ASN1_TIME_new()));
/* Dec 19, 2010, 18:10:11 */
AssertIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1);
AssertIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1);
AssertIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), WOLFSSL_SUCCESS);
AssertIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), WOLFSSL_SUCCESS);
AssertIntEQ(daysDiff, 2856);
AssertIntEQ(secsDiff, 75296);
/* Edge case with Unix epoch. */
AssertNotNull(ASN1_TIME_set_string(fromTime, "19700101000000Z"));
AssertNotNull(ASN1_TIME_set_string(toTime, "19800101000000Z"));
AssertIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), WOLFSSL_SUCCESS);
AssertIntEQ(daysDiff, 3652);
AssertIntEQ(secsDiff, 0);
ASN1_TIME_free(fromTime);
ASN1_TIME_free(toTime);