From owner-freebsd-bugs Fri Mar 15 12:40:19 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id 8C6A037B416 for ; Fri, 15 Mar 2002 12:40:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g2FKe2c60934; Fri, 15 Mar 2002 12:40:02 -0800 (PST) (envelope-from gnats) Date: Fri, 15 Mar 2002 12:40:02 -0800 (PST) Message-Id: <200203152040.g2FKe2c60934@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Maxim Konovalov Subject: Re: bin/35929: A small bug in renice Reply-To: Maxim Konovalov Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org The following reply was made to PR bin/35929; it has been noted by GNATS. From: Maxim Konovalov To: "Alexander S. Usov" Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/35929: A small bug in renice Date: Fri, 15 Mar 2002 23:36:35 +0300 (MSK) Could you please try a patch below (mostly from NetBSD): Index: renice.c =================================================================== RCS file: /home/ncvs/src/usr.bin/renice/renice.c,v retrieving revision 1.7 diff -u -r1.7 renice.c --- renice.c 3 Dec 2001 21:18:12 -0000 1.7 +++ renice.c 15 Mar 2002 20:31:46 -0000 @@ -56,8 +56,9 @@ #include #include -int donice __P((int, int, int)); -static void usage __P((void)); +static int getnum(const char *, const char *, int *); +static int donice(int, int, int); +static void usage(void); /* * Change the priority (nice) of processes @@ -75,7 +76,8 @@ argc--, argv++; if (argc < 2) usage(); - prio = atoi(*argv); + if (getnum("priority", *argv, &prio)) + return 1; argc--, argv++; if (prio > PRIO_MAX) prio = PRIO_MAX; @@ -95,7 +97,7 @@ continue; } if (which == PRIO_USER) { - register struct passwd *pwd = getpwnam(*argv); + struct passwd *pwd = getpwnam(*argv); if (pwd == NULL) { warnx("%s: unknown user", *argv); @@ -103,7 +105,8 @@ } who = pwd->pw_uid; } else { - who = atoi(*argv); + if (getnum("pid", *argv, &who)) + continue; if (who < 0) { warnx("%s: bad value", *argv); continue; @@ -114,21 +117,35 @@ exit(errs != 0); } -static void -usage() +static int +getnum(const char *com, const char *str, int *val) { - fprintf(stderr, -"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n"); - exit(1); + long v; + char *ep; + + v = strtol(str, &ep, NULL); + + if (*ep) { + warnx("Bad %s argument: %s", com, str); + return 1; + } + if ((v == LONG_MIN || v == LONG_MAX) && errno == ERANGE) { + warn("Invalid %s argument: %s", com, str); + return 1; + } + + *val = (int)v; + return 0; } -int +static int donice(which, who, prio) int which, who, prio; { int oldprio; - errno = 0, oldprio = getpriority(which, who); + errno = 0; + oldprio = getpriority(which, who); if (oldprio == -1 && errno) { warn("%d: getpriority", who); return (1); @@ -137,6 +154,15 @@ warn("%d: setpriority", who); return (1); } - printf("%d: old priority %d, new priority %d\n", who, oldprio, prio); + (void)printf("%d: old priority %d, new priority %d\n", who, oldprio, + prio); return (0); +} + +static void +usage() +{ + (void)fprintf(stderr, +"usage: renice priority [ [ -p ] pids ] [ [ -g ] pgrps ] [ [ -u ] users ]\n"); + exit(1); } -- Maxim Konovalov, MAcomnet, Internet-Intranet Dept., system engineer phone: +7 (095) 796-9079, mailto:maxim@macomnet.ru To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message