tload: validate numeric user input

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-12-18 14:29:19 +01:00
parent 7f99096ded
commit 9047933b2d
2 changed files with 10 additions and 2 deletions

View File

@ -66,6 +66,7 @@ endif
kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c kill_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
skill_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 snice_SOURCES = skill.c $(top_srcdir)/lib/strutils.c
tload_SOURCES = tload.c $(top_srcdir)/lib/strutils.c
pkill_SOURCES = pgrep.c pkill_SOURCES = pgrep.c
sysconf_DATA = sysctl.conf sysconf_DATA = sysctl.conf

11
tload.c
View File

@ -13,6 +13,7 @@
#include "proc/sysinfo.h" #include "proc/sysinfo.h"
#include "c.h" #include "c.h"
#include "nls.h" #include "nls.h"
#include "strutils.h"
#include "xalloc.h" #include "xalloc.h"
#include <errno.h> #include <errno.h>
@ -33,7 +34,7 @@ static int nrows = 25;
static int ncols = 80; static int ncols = 80;
static int scr_size; static int scr_size;
static int fd = 1; static int fd = 1;
static int dly = 5; static unsigned int dly = 5;
static jmp_buf jb; static jmp_buf jb;
static void alrm(int signo __attribute__ ((__unused__))) static void alrm(int signo __attribute__ ((__unused__)))
@ -88,6 +89,7 @@ int main(int argc, char **argv)
double av[3]; double av[3];
static double max_scale, scale_fact; static double max_scale, scale_fact;
char *scale_arg = NULL; char *scale_arg = NULL;
long tmpdly;
static const struct option longopts[] = { static const struct option longopts[] = {
{"scale", required_argument, NULL, 's'}, {"scale", required_argument, NULL, 's'},
@ -108,7 +110,12 @@ int main(int argc, char **argv)
scale_arg = optarg; scale_arg = optarg;
break; break;
case 'd': 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; break;
case 'V': case 'V':
printf(PROCPS_NG_VERSION); printf(PROCPS_NG_VERSION);