From owner-svn-src-all@freebsd.org Mon Jun 4 23:17:19 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id ADD43FE3A0B; Mon, 4 Jun 2018 23:17:19 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 613026D060; Mon, 4 Jun 2018 23:17:19 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3C1491401F; Mon, 4 Jun 2018 23:17:19 +0000 (UTC) (envelope-from np@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w54NHJWl045180; Mon, 4 Jun 2018 23:17:19 GMT (envelope-from np@FreeBSD.org) Received: (from np@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w54NHJAB045179; Mon, 4 Jun 2018 23:17:19 GMT (envelope-from np@FreeBSD.org) Message-Id: <201806042317.w54NHJAB045179@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: np set sender to np@FreeBSD.org using -f From: Navdeep Parhar Date: Mon, 4 Jun 2018 23:17:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334645 - head/usr.sbin/cxgbetool X-SVN-Group: head X-SVN-Commit-Author: np X-SVN-Commit-Paths: head/usr.sbin/cxgbetool X-SVN-Commit-Revision: 334645 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Jun 2018 23:17:19 -0000 Author: np Date: Mon Jun 4 23:17:18 2018 New Revision: 334645 URL: https://svnweb.freebsd.org/changeset/base/334645 Log: cxgbetool: Disallow negative values for numeric parameters. Sponsored by: Chelsio Communications Modified: head/usr.sbin/cxgbetool/cxgbetool.c Modified: head/usr.sbin/cxgbetool/cxgbetool.c ============================================================================== --- head/usr.sbin/cxgbetool/cxgbetool.c Mon Jun 4 22:39:22 2018 (r334644) +++ head/usr.sbin/cxgbetool/cxgbetool.c Mon Jun 4 23:17:18 2018 (r334645) @@ -606,31 +606,33 @@ static int parse_val_mask(const char *param, const char *args[], uint32_t *val, uint32_t *mask, int hashfilter) { + long l; char *p; if (strcmp(param, args[0]) != 0) return (EINVAL); - *val = strtoul(args[1], &p, 0); - if (p > args[1]) { - if (p[0] == 0) { - *mask = ~0; - return (0); - } + p = str_to_number(args[1], &l, NULL); + if (l >= 0 && l <= UINT32_MAX) { + *val = (uint32_t)l; + if (p > args[1]) { + if (p[0] == 0) { + *mask = ~0; + return (0); + } - if (p[0] == ':' && p[1] != 0) { - if (hashfilter) { - warnx("param %s: mask not allowed for " - "hashfilter or nat params", param); - return (EINVAL); + if (p[0] == ':' && p[1] != 0) { + if (hashfilter) { + warnx("param %s: mask not allowed for " + "hashfilter or nat params", param); + return (EINVAL); + } + p = str_to_number(p + 1, &l, NULL); + if (l >= 0 && l <= UINT32_MAX && p[0] == 0) { + *mask = (uint32_t)l; + return (0); + } } - *mask = strtoul(p+1, &p, 0); - if (p[0] == 0) - return (0); - } else { - warnx("param %s: mask not allowed for hashfilter", - param); - return (EINVAL); } } @@ -767,16 +769,19 @@ static int parse_val(const char *param, const char *args[], uint32_t *val) { char *p; + long l; if (strcmp(param, args[0]) != 0) return (EINVAL); - *val = strtoul(args[1], &p, 0); - if (p > args[1] && p[0] == 0) - return (0); + p = str_to_number(args[1], &l, NULL); + if (*p || l < 0 || l > UINT32_MAX) { + warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]); + return (EINVAL); + } - warnx("parameter \"%s\" has bad \"value\" %s", args[0], args[1]); - return (EINVAL); + *val = (uint32_t)l; + return (0); } static void