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 *.
This commit is contained in:
Luke Howard
2021-08-27 16:08:54 +10:00
parent 774f50b28b
commit ed1ef5d776

View File

@@ -97,7 +97,8 @@ der_print_generalized_time(const time_t *t, int flags)
char str[sizeof("1970-01-01T00:00:00Z")]; char str[sizeof("1970-01-01T00:00:00Z")];
#ifdef WIN32 #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; return NULL;
#else #else
if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_r(t, &tms)) == 0) 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")]; char str[sizeof("1970-01-01T00:00:00Z")];
#ifdef WIN32 #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; return NULL;
#else #else
if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_r(t, &tms)) == 0) if (strftime(str, sizeof(str), "%Y-%m-%dT%H:%M:%SZ", gmtime_r(t, &tms)) == 0)