From owner-svn-src-stable-10@freebsd.org Wed Jun 8 17:32:42 2016 Return-Path: Delivered-To: svn-src-stable-10@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C2BF3B6F482; Wed, 8 Jun 2016 17:32:42 +0000 (UTC) (envelope-from ngie@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 mx1.freebsd.org (Postfix) with ESMTPS id 83AE519A5; Wed, 8 Jun 2016 17:32:42 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u58HWfUB032855; Wed, 8 Jun 2016 17:32:41 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u58HWfLi032854; Wed, 8 Jun 2016 17:32:41 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201606081732.u58HWfLi032854@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Garrett Cooper Date: Wed, 8 Jun 2016 17:32:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r301656 - stable/10/usr.sbin/bsnmpd/tools/libbsnmptools X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2016 17:32:42 -0000 Author: ngie Date: Wed Jun 8 17:32:41 2016 New Revision: 301656 URL: https://svnweb.freebsd.org/changeset/base/301656 Log: MFC r299778: Use a consistent errno save/restore pattern before running strtoul - Save errno - Set errno to 0 - Call strtoul - Test errno (optional, but many calls to strtoul did this afterwards) Some of the code was setting errno = 0 after calling strtoul, not setting errno = 0, or setting errno to saved_errno after the call, but before the test. These all have unwanted behavioral side-effects, depending on the initial value of errno and whether or not the input to strtoul was correct or incorrect. Modified: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c ============================================================================== --- stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c Wed Jun 8 17:30:29 2016 (r301655) +++ stable/10/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c Wed Jun 8 17:32:41 2016 (r301656) @@ -364,6 +364,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'MM-' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -377,6 +378,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'DD,' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -390,6 +392,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'HH:' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -403,6 +406,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'MM:' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -416,6 +420,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'SS.' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -429,6 +434,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'M(mseconds),' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -454,6 +460,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'HH:' */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -467,6 +474,7 @@ snmp_date2asn_oid(char *str, struct asn_ /* 'MM' - last one - ignore endptr here. */ ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0) goto error; @@ -725,6 +733,7 @@ snmp_ntp_ts2asn_oid(char *str, struct as ptr = str; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { warnx("Integer value %s not supported", str); @@ -749,6 +758,7 @@ snmp_ntp_ts2asn_oid(char *str, struct as ptr = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { warnx("Integer value %s not supported", str); @@ -776,6 +786,7 @@ parse_ntp_ts(struct snmp_value *sv, char uint8_t ntp_ts[SNMP_NTP_TS_OCTETS]; saved_errno = errno; + errno = 0; v = strtoul(val, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { errno = saved_errno; @@ -797,6 +808,7 @@ parse_ntp_ts(struct snmp_value *sv, char val = endptr + 1; saved_errno = errno; + errno = 0; v = strtoul(val, &endptr, 10); if (errno != 0 || (v / 1000) > 9) { errno = saved_errno; @@ -879,8 +891,8 @@ snmp_bridgeid2oct(char *str, struct asn_ ptr = str; /* Read the priority. */ saved_errno = errno; - v = strtoul(ptr, &endptr, 10); errno = 0; + v = strtoul(ptr, &endptr, 10); if (v > SNMP_MAX_BRIDGE_PRIORITY || errno != 0 || *endptr != '.') { errno = saved_errno; @@ -897,6 +909,7 @@ snmp_bridgeid2oct(char *str, struct asn_ ptr = endptr + 1; for (i = 0; i < 5; i++) { saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 16); errno = saved_errno; if (v > 0xff) { @@ -914,6 +927,7 @@ snmp_bridgeid2oct(char *str, struct asn_ /* The last one - don't check the ending char here. */ saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 16); errno = saved_errno; if (v > 0xff) { @@ -938,7 +952,6 @@ parse_bridge_id(struct snmp_value *sv, c saved_errno = errno; errno = 0; v = strtoul(string, &endptr, 10); - errno = saved_errno; if (v > SNMP_MAX_BRIDGE_PRIORITY || errno != 0 || *endptr != '.') { errno = saved_errno; @@ -1026,8 +1039,8 @@ snmp_bport_id2oct(char *str, struct asn_ ptr = str; /* Read the priority. */ saved_errno = errno; - v = strtoul(ptr, &endptr, 10); errno = 0; + v = strtoul(ptr, &endptr, 10); if (v > SNMP_MAX_BPORT_PRIORITY || errno != 0 || *endptr != '.') { errno = saved_errno; @@ -1039,6 +1052,7 @@ snmp_bport_id2oct(char *str, struct asn_ return (NULL); saved_errno = errno; + errno = 0; v = strtoul(ptr, &endptr, 16); errno = saved_errno; @@ -1065,7 +1079,6 @@ parse_bport_id(struct snmp_value *value, saved_errno = errno; errno = 0; v = strtoul(string, &endptr, 10); - errno = saved_errno; if (v > SNMP_MAX_BPORT_PRIORITY || errno != 0 || *endptr != '.') { errno = saved_errno;