]> granicus.if.org Git - procps-ng/commitdiff
0009-uptime: Check the return value of various functions.
authorQualys Security Advisory <qsa@qualys.com>
Thu, 1 Jan 1970 00:00:00 +0000 (00:00 +0000)
committerCraig Small <csmall@enc.com.au>
Sat, 23 Jun 2018 11:59:14 +0000 (21:59 +1000)
uptime.c

index be3d01a9d2a8f37dda1b9dedabef894ae8090f41..6134950ed7c7b0005995aa362c27efbd1510af54 100644 (file)
--- a/uptime.c
+++ b/uptime.c
@@ -37,15 +37,18 @@ static void print_uptime_since()
     struct timeval tim;
 
     /* Get the current time and convert it to a double */
-    gettimeofday(&tim, NULL);
+       if (gettimeofday(&tim, NULL) != 0)
+        xerr(EXIT_FAILURE, "gettimeofday");
     now = tim.tv_sec + (tim.tv_usec / 1000000.0);
 
     /* Get the uptime and calculate when that was */
-    procps_uptime(&uptime_secs, &idle_secs);
+       if (procps_uptime(&uptime_secs, &idle_secs) < 0)
+               xerrx(EXIT_FAILURE, "uptime");
     up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
 
     /* Show this */
-    up_since = localtime(&up_since_secs);
+       if ((up_since = localtime(&up_since_secs)) == NULL)
+               xerrx(EXIT_FAILURE, "localtime");
     printf("%04d-%02d-%02d %02d:%02d:%02d\n",
         up_since->tm_year + 1900, up_since->tm_mon + 1, up_since->tm_mday,
         up_since->tm_hour, up_since->tm_min, up_since->tm_sec);