From: Todd C. Miller Date: Tue, 24 Feb 2015 16:53:50 +0000 (-0700) Subject: Check clock_gettime() return value and warn if it fails. X-Git-Tag: SUDO_1_8_13^2~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=01a4d6ccbf9cc9fc3d65763f37fc8cb8f612f55a;p=sudo Check clock_gettime() return value and warn if it fails. Currently, the timestamp will be ignored if clock_gettime() fails. --- diff --git a/include/sudo_compat.h b/include/sudo_compat.h index 097e6b6ba..49b6e732f 100644 --- a/include/sudo_compat.h +++ b/include/sudo_compat.h @@ -460,8 +460,10 @@ __dso_public int sudo_sig2str(int signo, char *signame); # define sig2str(_a, _b) sudo_sig2str((_a), (_b)) #endif /* HAVE_SIG2STR */ #ifndef HAVE_CLOCK_GETTIME -# define CLOCK_REALTIME 0 -# ifdef __MACH__ +# if !defined(CLOCK_REALTIME) +# define CLOCK_REALTIME 0 +# endif +# if defined(__MACH__) && !defined(CLOCK_MONOTONIC) # define CLOCK_MONOTONIC 1 # endif __dso_public int sudo_clock_gettime(clockid_t clock_id, struct timespec *tp); diff --git a/plugins/sudoers/timestamp.c b/plugins/sudoers/timestamp.c index 39496925a..05e08ff1a 100644 --- a/plugins/sudoers/timestamp.c +++ b/plugins/sudoers/timestamp.c @@ -345,7 +345,10 @@ update_timestamp(struct passwd *pw) /* Fill in time stamp. */ memcpy(&entry, ×tamp_key, sizeof(struct timestamp_entry)); - clock_gettime(SUDO_CLOCK_MONOTONIC, &entry.ts); + if (clock_gettime(SUDO_CLOCK_MONOTONIC, &entry.ts) == -1) { + log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC); + goto done; + } /* Open time stamp file and lock it for exclusive access. */ if (timestamp_uid != 0) @@ -427,7 +430,10 @@ timestamp_status(struct passwd *pw) timestamp_key.u.ppid = getppid(); } } - clock_gettime(SUDO_CLOCK_MONOTONIC, ×tamp_key.ts); + if (clock_gettime(SUDO_CLOCK_MONOTONIC, ×tamp_key.ts) == -1) { + log_warning(0, "clock_gettime(%d)", SUDO_CLOCK_MONOTONIC); + status = TS_ERROR; + } /* If the time stamp dir is missing there is nothing to do. */ if (status == TS_MISSING)