mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 16:45:07 -05:00
util: check for gmtime() error
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.
This commit is contained in:
10
util.c
10
util.c
@@ -610,13 +610,17 @@ UTI_SockaddrFamilyToString(int family)
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user