From ed1ef5d7760b6c2cc88f885c049c764628c6efaf Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Fri, 27 Aug 2021 16:08:54 +1000 Subject: [PATCH] asn1: correctly check gmtime_s() return value gmtime_s(), used on Windows, returns an errno_t not a struct tm *. The previous code caused strftime() to dereference a NULL struct tm *. --- lib/asn1/der_print.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/asn1/der_print.c b/lib/asn1/der_print.c index 84fded31a..02d8dab05 100644 --- a/lib/asn1/der_print.c +++ b/lib/asn1/der_print.c @@ -97,7 +97,8 @@ der_print_generalized_time(const time_t *t, int flags) char str[sizeof("1970-01-01T00:00:00Z")]; #ifdef WIN32 - if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_s(&tms, t)) == 0) + if (gmtime_s(&tms, t) != 0 || + strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", &tms) == 0) return NULL; #else if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_r(t, &tms)) == 0) @@ -113,7 +114,8 @@ der_print_utctime(const time_t *t, int flags) char str[sizeof("1970-01-01T00:00:00Z")]; #ifdef WIN32 - if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_s(&tms, t)) == 0) + if (gmtime_s(&tms, t) != 0 || + strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", &tms) == 0) return NULL; #else if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_r(t, &tms)) == 0)