Merge pull request #4959 from haydenroche5/asn1_time_diff_bug

Fix bug in wolfSSL_ASN1_TIME_diff.
pull/4972/head
David Garske 2022-03-18 14:28:23 -07:00 committed by GitHub
commit a79daa5ea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

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

View File

@ -30620,15 +30620,23 @@ static void test_wolfSSL_ASN1_TIME_diff(void)
AssertNotNull((fromTime = ASN1_TIME_new())); AssertNotNull((fromTime = ASN1_TIME_new()));
/* Feb 22, 2003, 21:15:15 */ /* 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())); AssertNotNull((toTime = ASN1_TIME_new()));
/* Dec 19, 2010, 18:10:11 */ /* Dec 19, 2010, 18:10:11 */
AssertIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), 1); AssertIntEQ(ASN1_TIME_set_string(toTime, "101219181011Z"), WOLFSSL_SUCCESS);
AssertIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), 1); AssertIntEQ(ASN1_TIME_diff(&daysDiff, &secsDiff, fromTime, toTime), WOLFSSL_SUCCESS);
AssertIntEQ(daysDiff, 2856); AssertIntEQ(daysDiff, 2856);
AssertIntEQ(secsDiff, 75296); 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(fromTime);
ASN1_TIME_free(toTime); ASN1_TIME_free(toTime);