Fix the UTI_TimeToLogForm() function to check if gmtime() didn't fail.
This caused chronyc to crash due to dereferencing a NULL pointer when
a response to the "manual list" request contained time which gmtime()
could not convert to broken-down representation.
This issue was found in an audit performed by Cure53 and sponsored by
Mozilla.
char *
UTI_TimeToLogForm(time_t t)
{
- struct tm stm;
+ struct tm *stm;
char *result;
result = NEXT_BUFFER;
- stm = *gmtime(&t);
- strftime(result, BUFFER_LENGTH, "%Y-%m-%d %H:%M:%S", &stm);
+ stm = gmtime(&t);
+
+ if (stm)
+ strftime(result, BUFFER_LENGTH, "%Y-%m-%d %H:%M:%S", stm);
+ else
+ snprintf(result, BUFFER_LENGTH, "INVALID INVALID ");
return result;
}