]> granicus.if.org Git - sudo/commitdiff
Check the return value of gettimeofday(), even though it should
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 25 Feb 2015 14:10:25 +0000 (07:10 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 25 Feb 2015 14:10:25 +0000 (07:10 -0700)
never fail.

plugins/sudoers/iolog.c
plugins/sudoers/visudo.c
src/sudo_edit.c
src/utmp.c

index f43901eaf17a5dcf921613f0261d0ab5cb67ae15..48a5c2d4959dd781af04def9e68bafbca1287e1e 100644 (file)
@@ -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. */
index c5270af35094287cc20666e477801263e7f29bcd..1c54897c49043a7d4b86e0e6ee1d1284d9e7acff 100644 (file)
@@ -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(&times[0], NULL);
+    if (gettimeofday(&times[0], NULL) == -1) {
+       sudo_warn(U_("unable to read the clock"));
+       goto done;
+    }
+
     if (run_command(editor, av) != -1) {
-       gettimeofday(&times[1], NULL);
+       if (gettimeofday(&times[1], NULL) == -1) {
+           sudo_warn(U_("unable to read the clock"));
+           goto done;
+       }
        /*
         * Sanity checks.
         */
index a1d8ecb2ecc7cf0b84d5045436358e0915c51fc5..acacfde92b508e8a6071db741bf9d7e18ab245a3 100644 (file)
@@ -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(&times[0], NULL);
+    if (gettimeofday(&times[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(&times[1], NULL);
+    if (gettimeofday(&times[1], NULL) == -1) {
+       sudo_warn(U_("unable to read the clock"));
+       goto cleanup;
+    }
 
     /* Restore saved command_details. */
     command_details->uid = saved_command_details.uid;
index 09a6098aed1177ab1466848bab95a10dbb73689e..053d38de2f6d835d91055a09ce3ca61f8a1ba386 100644 (file)
@@ -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;
 }