From 57d978dcf89cc0b587c4ddbd59df324daea2459d Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Sun, 6 Jan 2008 19:53:56 -0700 Subject: [PATCH] renice: correctly detect errors in arguments renice was using atoi(), which does no error detection, meaning that: "renice +20 blah" was accepted as valid. Addresses-Debian-Bug: 385245 Signed-off-by: LaMont Jones --- sys-utils/renice.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/sys-utils/renice.c b/sys-utils/renice.c index 2807ae3b..a8bf73d9 100644 --- a/sys-utils/renice.c +++ b/sys-utils/renice.c @@ -48,6 +48,12 @@ int donice(int,int,int); +void usage(void) +{ + fprintf(stderr, _("usage: renice priority [ [ -p ] pids ] " + "[ [ -g ] pgrps ] [ [ -u ] users ]\n")); + exit(1); +} /* * Change the priority (nice) of processes * or groups of processes which are already @@ -58,6 +64,7 @@ main(int argc, char **argv) { int which = PRIO_PROCESS; int who = 0, prio, errs = 0; + char *endptr=NULL; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -65,11 +72,12 @@ main(int argc, char **argv) argc--, argv++; if (argc < 2) { - fprintf(stderr, _("usage: renice priority [ [ -p ] pids ] " - "[ [ -g ] pgrps ] [ [ -u ] users ]\n")); - exit(1); + usage(); + } + prio = strtol(*argv,&endptr,10); + if (*endptr) { + usage(); } - prio = atoi(*argv); argc--, argv++; #if 0 if (prio > PRIO_MAX) @@ -100,8 +108,8 @@ main(int argc, char **argv) } who = pwd->pw_uid; } else { - who = atoi(*argv); - if (who < 0) { + who = strtol(*argv,&endptr,10); + if (who < 0 || *endptr) { fprintf(stderr, _("renice: %s: bad value\n"), *argv); continue; -- 2.39.5