From 973286c7aceab44b904ea0de7f3a319df40c4f0b Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Wed, 25 Feb 2015 07:10:25 -0700 Subject: [PATCH] Check the return value of gettimeofday(), even though it should never fail. --- plugins/sudoers/iolog.c | 3 ++- plugins/sudoers/visudo.c | 11 +++++++++-- src/sudo_edit.c | 10 ++++++++-- src/utmp.c | 10 +++++----- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index f43901eaf..48a5c2d49 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -636,7 +636,8 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, goto done; /* Write log file with user and command details. */ - gettimeofday(&last_time, NULL); + if (gettimeofday(&last_time, NULL) == -1) + goto done; write_info_log(pathbuf, len, &details, argv, &last_time); /* Create the timing and I/O log files. */ diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index c5270af35..1c54897c4 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -429,9 +429,16 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) * XPG4 specifies that vi's exit value is a function of the * number of errors during editing (?!?!). */ - gettimeofday(×[0], NULL); + if (gettimeofday(×[0], NULL) == -1) { + sudo_warn(U_("unable to read the clock")); + goto done; + } + if (run_command(editor, av) != -1) { - gettimeofday(×[1], NULL); + if (gettimeofday(×[1], NULL) == -1) { + sudo_warn(U_("unable to read the clock")); + goto done; + } /* * Sanity checks. */ diff --git a/src/sudo_edit.c b/src/sudo_edit.c index a1d8ecb2e..acacfde92 100644 --- a/src/sudo_edit.c +++ b/src/sudo_edit.c @@ -600,7 +600,10 @@ sudo_edit(struct command_details *command_details) * Run the editor with the invoking user's creds, * keeping track of the time spent in the editor. */ - gettimeofday(×[0], NULL); + if (gettimeofday(×[0], NULL) == -1) { + sudo_warn(U_("unable to read the clock")); + goto cleanup; + } memcpy(&saved_command_details, command_details, sizeof(struct command_details)); command_details->uid = user_details.uid; command_details->euid = user_details.uid; @@ -610,7 +613,10 @@ sudo_edit(struct command_details *command_details) command_details->groups = user_details.groups; command_details->argv = nargv; rval = run_command(command_details); - gettimeofday(×[1], NULL); + if (gettimeofday(×[1], NULL) == -1) { + sudo_warn(U_("unable to read the clock")); + goto cleanup; + } /* Restore saved command_details. */ command_details->uid = saved_command_details.uid; diff --git a/src/utmp.c b/src/utmp.c index 09a6098ae..053d38de2 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -126,14 +126,14 @@ utmp_settime(sudo_utmp_t *ut) struct timeval tv; debug_decl(utmp_settime, SUDO_DEBUG_UTMP) - gettimeofday(&tv, NULL); - + if (gettimeofday(&tv, NULL) == 0) { #if defined(HAVE_STRUCT_UTMP_UT_TV) || defined(HAVE_STRUCT_UTMPX_UT_TV) - ut->ut_tv.tv_sec = tv.tv_sec; - ut->ut_tv.tv_usec = tv.tv_usec; + ut->ut_tv.tv_sec = tv.tv_sec; + ut->ut_tv.tv_usec = tv.tv_usec; #else - ut->ut_time = tv.tv_sec; + ut->ut_time = tv.tv_sec; #endif + } debug_return; } -- 2.40.0