From owner-svn-src-head@FreeBSD.ORG Fri Sep 26 01:03:24 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 24214CC1; Fri, 26 Sep 2014 01:03:24 +0000 (UTC) Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [IPv6:2a00:1450:400c:c05::22e]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4279AC52; Fri, 26 Sep 2014 01:03:23 +0000 (UTC) Received: by mail-wi0-f174.google.com with SMTP id hi2so84129wib.13 for ; Thu, 25 Sep 2014 18:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=MpvF8PB7DxhFbD7IZ1my7r37Cf5w0mYwDPIeH6JLayY=; b=fA75dnZjdABz5X6Sat/A/My/UTsmmyJTPR5v6Lpx9JhjdpBd5UBebCXm8BcAOnGjLc wtCyVAn82c8TLaW7arTrn+to0Gc0psjRcekfGL+3GqjgWq5y1FVCypfDXDoFVZPbUrgy ZJNkc2dF0gXB/JCGrXMGeFJhkcoewNNtlIfLppp6qLx/Hr5RrRo+qmx4JRGD2ad39IfH Yq1GIloCi2MTtu9ezvY9hffHUB12KWPNxyRxIcaA60atlf1fEO9b1SofeJt/UFhonup0 8g1XvJU8ve/ROqwrbFJ+no+79mfdUezGnChfOxOzaf1ulXQAceVsGpNGySRAite92cwA jetA== X-Received: by 10.194.89.67 with SMTP id bm3mr20652674wjb.80.1411693401439; Thu, 25 Sep 2014 18:03:21 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id ic7sm455466wid.11.2014.09.25.18.03.20 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Sep 2014 18:03:20 -0700 (PDT) Date: Fri, 26 Sep 2014 03:03:18 +0200 From: Mateusz Guzik To: d@delphij.net Subject: Re: svn commit: r272144 - head/sbin/sysctl Message-ID: <20140926010317.GA21954@dft-labs.eu> References: <201409252237.s8PMbScl041679@svn.freebsd.org> <20140925224035.GA6065@dft-labs.eu> <5424B11E.4030909@delphij.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <5424B11E.4030909@delphij.net> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, Xin LI X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Sep 2014 01:03:24 -0000 On Thu, Sep 25, 2014 at 05:19:42PM -0700, Xin Li wrote: > - if (newval == NULL || dflag) { > + if (newvalstr == NULL || dflag) { > if ((kind & CTLTYPE) == CTLTYPE_NODE) { > if (dflag) { > i = show_var(mib, len); > @@ -288,10 +314,22 @@ parse(const char *string, int lineno) > (kind & CTLTYPE) == CTLTYPE_ULONG || > (kind & CTLTYPE) == CTLTYPE_S64 || > (kind & CTLTYPE) == CTLTYPE_U64) { > - if (strlen(newval) == 0) { > + if (strlen(newvalstr) == 0) { > warnx("empty numeric value"); > return (1); > } > + } else if ((kind & CTLTYPE) != CTLTYPE_STRING) { > + /* > + * The only acceptable types are: > + * CTLTYPE_INT, CTLTYPE_UINT, > + * CTLTYPE_LONG, CTLTYPE_ULONG, > + * CTLTYPE_S64, CTLTYPE_U64 and > + * CTLTYPE_STRING. > + */ > + warnx("oid '%s' is type %d," > + " cannot set that%s", bufp, > + kind & CTLTYPE, line); > + return (1); > } I think this should be converted to switch, +/-: switch (kind & CTLTYPE) { case CTLTYPE_INT: case CTLTYPE_UINT: case CTLTYPE_LONG: case CTLTYPE_ULONG: case CTLTYPE_S64: case CTLTYPE_U64: if (strlen(newvalstr) == 0) { warnx("empty numeric value"); return (1); } break; case CTLTYPE_STRING: break; default: warnx("oid '%s' is type %d cannot set that%s", bufp, kind & CTLTYPE, line); return (1); } > > errno = 0; > @@ -298,91 +336,53 @@ parse(const char *string, int lineno) > > switch (kind & CTLTYPE) { > default: > - warnx("oid '%s' is type %d," > - " cannot set that%s", bufp, > - kind & CTLTYPE, line); > + /* NOTREACHED */ > return (1); This one should be removed or should call abort() or something since it should be impossible to get here. > } > > + if (errno != 0 || endptr == newvalstr || *endptr != '\0') { > + warnx("invalid %s '%s'%s", ctl_typename[kind & CTLTYPE], > + newvalstr, line); > + return (1); > + } > + So one thing a big fan of is the fact that some values are still assigned based on possibly bogus result. Some static analysis tool may object. But it's just a note. In general I think it's fine. > i = show_var(mib, len); > if (sysctl(mib, len, 0, 0, newval, newsize) == -1) { > if (!i && !bflag) > @@ -665,33 +665,35 @@ S_bios_smap_xattr(size_t l2, void *p) > #endif > -- Mateusz Guzik