[PATCH] renice: correctly detect errors in arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <lamont@xxxxxxxxxx>
---
 sys-utils/renice.c |   20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/sys-utils/renice.c b/sys-utils/renice.c
index 2807ae3..a8bf73d 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;
-- 
1.5.3.6

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux