diff --git a/lib/eventlog/eventlog.c b/lib/eventlog/eventlog.c index f5245e66a..9f47c999e 100644 --- a/lib/eventlog/eventlog.c +++ b/lib/eventlog/eventlog.c @@ -900,10 +900,12 @@ format_json(int event_type, struct eventlog_args *args, } /* Log event time from client */ - if (!json_add_timestamp(&json, time_str, args->event_time, format_timestamp)) { - sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, - "unable format timestamp"); - goto bad; + if (args->event_time != NULL) { + if (!json_add_timestamp(&json, time_str, args->event_time, format_timestamp)) { + sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, + "unable format timestamp"); + goto bad; + } } if (event_type == EVLOG_EXIT) { @@ -1136,7 +1138,6 @@ do_logfile_sudo(const char *logline, const struct eventlog *evlog, char *full_line, timebuf[8192], *timestr = NULL; const char *timefmt = evl_conf->time_fmt; const char *logfile = evl_conf->logpath; - time_t tv_sec = event_time->tv_sec; struct tm tm; bool ret = false; FILE *fp; @@ -1152,12 +1153,15 @@ do_logfile_sudo(const char *logline, const struct eventlog *evlog, goto done; } - if (localtime_r(&tv_sec, &tm) != NULL) { - /* strftime() does not guarantee to NUL-terminate so we must check. */ - timebuf[sizeof(timebuf) - 1] = '\0'; - if (strftime(timebuf, sizeof(timebuf), timefmt, &tm) != 0 && - timebuf[sizeof(timebuf) - 1] == '\0') { - timestr = timebuf; + if (event_time != NULL) { + time_t tv_sec = event_time->tv_sec; + if (localtime_r(&tv_sec, &tm) != NULL) { + /* strftime() does not guarantee to NUL-terminate so we must check. */ + timebuf[sizeof(timebuf) - 1] = '\0'; + if (strftime(timebuf, sizeof(timebuf), timefmt, &tm) != 0 && + timebuf[sizeof(timebuf) - 1] == '\0') { + timestr = timebuf; + } } } len = asprintf(&full_line, "%s : %s : %s", diff --git a/logsrvd/logsrvd_local.c b/logsrvd/logsrvd_local.c index 6b30f9d9f..ea0de8ad1 100644 --- a/logsrvd/logsrvd_local.c +++ b/logsrvd/logsrvd_local.c @@ -264,12 +264,16 @@ bool store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len, struct connection_closure *closure) { + struct timespec ts, *run_time = NULL; const char *signame = NULL; - struct timespec run_time = { msg->run_time->tv_sec, msg->run_time->tv_nsec }; int flags = 0; - mode_t mode; debug_decl(store_exit_local, SUDO_DEBUG_UTIL); + if (msg->run_time != NULL) { + ts.tv_sec = msg->run_time->tv_sec; + ts.tv_nsec = msg->run_time->tv_nsec; + run_time = &ts; + } if (msg->signal != NULL && msg->signal[0] != '\0') { signame = msg->signal; sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO, @@ -280,7 +284,7 @@ store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len, "command exited with %d", msg->exit_value); } if (logsrvd_conf_log_exit()) { - if (!eventlog_exit(closure->evlog, flags, &run_time, msg->exit_value, + if (!eventlog_exit(closure->evlog, flags, run_time, msg->exit_value, signame, msg->dumped_core)) { closure->errstr = _("error logging exit event"); debug_return_bool(false); @@ -289,7 +293,7 @@ store_exit_local(ExitMessage *msg, uint8_t *buf, size_t len, if (closure->log_io) { /* Clear write bits from I/O timing file to indicate completion. */ - mode = logsrvd_conf_iolog_mode(); + mode_t mode = logsrvd_conf_iolog_mode(); CLR(mode, S_IWUSR|S_IWGRP|S_IWOTH); if (fchmodat(closure->iolog_dir_fd, "timing", mode, 0) == -1) { sudo_warn("chmod 0%o %s/%s", (unsigned int)mode, "timing",