From 9047933b2dcb4c343cae8f4e56c454f335f54be9 Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Sun, 18 Dec 2011 14:29:19 +0100 Subject: [PATCH] tload: validate numeric user input Signed-off-by: Sami Kerola --- Makefile.am | 1 + tload.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 13154d5f..c156a8cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 ebd5e392..861375df 100644 --- 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 @@ -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);