]> granicus.if.org Git - procps-ng/commitdiff
tload: validate numeric user input
authorSami Kerola <kerolasa@iki.fi>
Sun, 18 Dec 2011 13:29:19 +0000 (14:29 +0100)
committerSami Kerola <kerolasa@iki.fi>
Tue, 20 Dec 2011 16:30:54 +0000 (17:30 +0100)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Makefile.am
tload.c

index 13154d5fd204334f458fac58b8fbf062acccc682..c156a8cdd6dffa45cec0239a05c45e7bc3894a01 100644 (file)
@@ -66,6 +66,7 @@ endif
 kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
 skill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
 snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
+tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
 pkill_SOURCES = pgrep.c
 
 sysconf_DATA = sysctl.conf
diff --git a/tload.c b/tload.c
index ebd5e392d9e9ae5da4e594138c05208383307f34..861375df09eaed21f751424677484a89ee4a3270 100644 (file)
--- a/tload.c
+++ b/tload.c
@@ -13,6 +13,7 @@
 #include "proc/sysinfo.h"
 #include "c.h"
 #include "nls.h"
+#include "strutils.h"
 #include "xalloc.h"
 
 #include <errno.h>
@@ -33,7 +34,7 @@ static int nrows = 25;
 static int ncols = 80;
 static int scr_size;
 static int fd = 1;
-static int dly = 5;
+static unsigned int dly = 5;
 static jmp_buf jb;
 
 static void alrm(int signo __attribute__ ((__unused__)))
@@ -88,6 +89,7 @@ int main(int argc, char **argv)
        double av[3];
        static double max_scale, scale_fact;
        char *scale_arg = NULL;
+       long tmpdly;
 
        static const struct option longopts[] = {
                {"scale", required_argument, NULL, 's'},
@@ -108,7 +110,12 @@ int main(int argc, char **argv)
                        scale_arg = optarg;
                        break;
                case 'd':
-                       dly = atoi(optarg);
+                       tmpdly = strtol_or_err(optarg, _("failed to parse argument"));
+                       if (tmpdly < 1)
+                               errx(EXIT_FAILURE, _("delay must be positive integer"));
+                       else if (UINT_MAX < tmpdly)
+                               errx(EXIT_FAILURE, _("too large delay value"));
+                       dly = tmpdly;
                        break;
                case 'V':
                        printf(PROCPS_NG_VERSION);