From owner-freebsd-hackers@FreeBSD.ORG Sun Jan 2 06:15:34 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B25AB106566C for ; Sun, 2 Jan 2011 06:15:34 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-iy0-f182.google.com (mail-iy0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id 8AD068FC0A for ; Sun, 2 Jan 2011 06:15:34 +0000 (UTC) Received: by iyb26 with SMTP id 26so11804177iyb.13 for ; Sat, 01 Jan 2011 22:15:33 -0800 (PST) Received: by 10.231.16.131 with SMTP id o3mr3214994iba.5.1293948933697; Sat, 01 Jan 2011 22:15:33 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.178.195 with HTTP; Sat, 1 Jan 2011 22:15:13 -0800 (PST) From: Eitan Adler Date: Sun, 2 Jan 2011 01:15:13 -0500 Message-ID: To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 Subject: [patch] have rtprio check that arguments are numeric; change atoi to strtol X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 Jan 2011 06:15:34 -0000 When looking at the rtprio(1) source I noticed that the dg in revision 3291 has indicated that he wanted to check to ensure that the user provided priority was numeric. Also the man page for atoi says the function is deprecated - so I replaced those functions as well. Index: rtprio.c =================================================================== --- rtprio.c (revision 216679) +++ rtprio.c (working copy) @@ -56,6 +56,7 @@ char *p; int proc = 0; struct rtprio rtp; + int c; /* find basename */ if ((p = rindex(argv[0], '/')) == NULL) @@ -70,8 +71,10 @@ switch (argc) { case 2: - proc = abs(atoi(argv[1])); /* Should check if numeric - * arg! */ + for (c=0; c < strlen(argv[1]); ++c) + if (!isdigit(argv[1][c])) + errx(1,"%s", "Priority should be a number"); + proc = (int)strtol(argv[1], (char **)NULL, 10); /* FALLTHROUGH */ case 1: if (rtprio(RTP_LOOKUP, proc, &rtp) != 0) @@ -104,7 +107,10 @@ break; } } else { - rtp.prio = atoi(argv[1]); + for (c=0; c < strlen(argv[1]); ++c) + if (!isdigit(argv[1][c])) + errx(1,"%s", "Priority should be a number"); + rtp.prio = (int)strtol(argv[1], (char **)NULL, 10); } } else { usage(); @@ -112,7 +118,7 @@ } if (argv[2][0] == '-') - proc = -atoi(argv[2]); + proc = -(int)strtol(argv[2], (char **)NULL, 10); if (rtprio(RTP_SET, proc, &rtp) != 0) err(1, "%s", argv[0]); -- Eitan Adler