From owner-svn-src-all@FreeBSD.ORG Thu Sep 25 22:40:45 2014 Return-Path: Delivered-To: svn-src-all@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 F1AE4B02; Thu, 25 Sep 2014 22:40:44 +0000 (UTC) Received: from mail-wg0-x22b.google.com (mail-wg0-x22b.google.com [IPv6:2a00:1450:400c:c00::22b]) (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 1D905BAE; Thu, 25 Sep 2014 22:40:43 +0000 (UTC) Received: by mail-wg0-f43.google.com with SMTP id y10so8876972wgg.2 for ; Thu, 25 Sep 2014 15:40:42 -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=SA5uociwHSyGMaGwnAIlO41qx3tnt5dvytvksFC69D8=; b=RzzRH1hOAd2UGRHpHZvuF1fy833kxj5l5CjaRuWcO3HzYbQSb9uAAEXcAESTSBOfi5 gUB9AagyU2I7BxzzmZVTJSZOKPAQF8vDuwVPQ6ojV9y0xDT22xtxid4bIWrLAYu9NEyx Xf5TTqO19lqoC5Igi25EEjPs2e0SlH6MM7dG2eM1m/LdtWiT4UNbLJD1AYfVxjmFOyBa 3gWbTqldHv7ND3o0DatsiemdSrASudWkK9gHXG6k63IxxOXmiyrZ6ge7DS16Y528ly6c SPsWg7olk1Rvp9QmxMEsw3NScW6sEFXD6uELp3I0vqIk+w8lNBTka7e2nJdZEqPzcrJ9 kuzg== X-Received: by 10.180.76.68 with SMTP id i4mr42650845wiw.64.1411684838953; Thu, 25 Sep 2014 15:40:38 -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 ju1sm4177266wjc.1.2014.09.25.15.40.37 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 25 Sep 2014 15:40:38 -0700 (PDT) Date: Fri, 26 Sep 2014 00:40:35 +0200 From: Mateusz Guzik To: Xin LI Subject: Re: svn commit: r272144 - head/sbin/sysctl Message-ID: <20140925224035.GA6065@dft-labs.eu> References: <201409252237.s8PMbScl041679@svn.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <201409252237.s8PMbScl041679@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 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: Thu, 25 Sep 2014 22:40:45 -0000 On Thu, Sep 25, 2014 at 10:37:28PM +0000, Xin LI wrote: > Author: delphij > Date: Thu Sep 25 22:37:27 2014 > New Revision: 272144 > URL: http://svnweb.freebsd.org/changeset/base/272144 > > Log: > The strtol(3) family of functions would set errno when it hits one. > Check errno and handle it as invalid input. > But this requires explicitely setting errno to 0 before strto* call, otherwise you cannot know whether errno is meaningful when you test it. Also it looks like the code would use some deduplications with macros or something. > Obtained from: HardenedBSD > Submitted by: David CARLIER > MFC after: 2 weeks > > Modified: > head/sbin/sysctl/sysctl.c > > Modified: head/sbin/sysctl/sysctl.c > ============================================================================== > --- head/sbin/sysctl/sysctl.c Thu Sep 25 22:22:57 2014 (r272143) > +++ head/sbin/sysctl/sysctl.c Thu Sep 25 22:37:27 2014 (r272144) > @@ -305,7 +305,8 @@ parse(const char *string, int lineno) > } else { > intval = (int)strtol(newval, &endptr, > 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid integer '%s'%s", > (char *)newval, line); > return (1); > @@ -316,7 +317,8 @@ parse(const char *string, int lineno) > break; > case CTLTYPE_UINT: > uintval = (int) strtoul(newval, &endptr, 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid unsigned integer '%s'%s", > (char *)newval, line); > return (1); > @@ -326,7 +328,8 @@ parse(const char *string, int lineno) > break; > case CTLTYPE_LONG: > longval = strtol(newval, &endptr, 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid long integer '%s'%s", > (char *)newval, line); > return (1); > @@ -336,7 +339,8 @@ parse(const char *string, int lineno) > break; > case CTLTYPE_ULONG: > ulongval = strtoul(newval, &endptr, 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid unsigned long integer" > " '%s'%s", (char *)newval, line); > return (1); > @@ -348,7 +352,8 @@ parse(const char *string, int lineno) > break; > case CTLTYPE_S64: > i64val = strtoimax(newval, &endptr, 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid int64_t '%s'%s", > (char *)newval, line); > return (1); > @@ -358,7 +363,8 @@ parse(const char *string, int lineno) > break; > case CTLTYPE_U64: > u64val = strtoumax(newval, &endptr, 0); > - if (endptr == newval || *endptr != '\0') { > + if (errno != 0 || endptr == newval || > + *endptr != '\0') { > warnx("invalid uint64_t '%s'%s", > (char *)newval, line); > return (1); > @@ -669,14 +675,16 @@ set_IK(const char *str, int *val) > p = &str[len - 1]; > if (*p == 'C' || *p == 'F') { > temp = strtof(str, &endptr); > - if (endptr == str || endptr != p) > + if (errno != 0 || endptr == str || > + endptr != p) > return (0); > if (*p == 'F') > temp = (temp - 32) * 5 / 9; > kelv = temp * 10 + 2732; > } else { > kelv = (int)strtol(str, &endptr, 10); > - if (endptr == str || *endptr != '\0') > + if (errno != 0 || endptr == str || > + *endptr != '\0') > return (0); > } > *val = kelv; > -- Mateusz Guzik