From owner-svn-src-all@FreeBSD.ORG Thu Sep 25 22:37:28 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 CE9988ED; Thu, 25 Sep 2014 22:37:28 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id AE95AB94; Thu, 25 Sep 2014 22:37:28 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8PMbSED041680; Thu, 25 Sep 2014 22:37:28 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8PMbScl041679; Thu, 25 Sep 2014 22:37:28 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201409252237.s8PMbScl041679@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Thu, 25 Sep 2014 22:37:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r272144 - head/sbin/sysctl X-SVN-Group: head 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.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:37:29 -0000 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. 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;