From owner-svn-src-all@freebsd.org Sun May 15 06:25:19 2016 Return-Path: Delivered-To: svn-src-all@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 8B4A3B3CAC1; Sun, 15 May 2016 06:25:19 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-oi0-f54.google.com (mail-oi0-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 5C9D2110A; Sun, 15 May 2016 06:25:19 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-oi0-f54.google.com with SMTP id x19so227391590oix.2; Sat, 14 May 2016 23:25:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc; bh=BdZJwQ0cq+kD0R0tQlPM6blIr5KVwwoDXZHtEV1YbB8=; b=A8cx9Mau2lqwkVsgRlzpDgZ+a5h0XoWOMVOdDlSHFtwMQobY35kary4TtvetXDRjYR 88NGorghI/rLKSvcRnqY99roohZVybEAiknPy7pRHJWungELu1s3urIOV2SVGWOIXTzx tBoH0/A1RrJ5tPSBRONE0P7VAYF/O3PTmPvKPeEoz7aM4pcFoFMfZOMPSvP/n48Xosf4 qK85CugsU7S1qrDQYPyj/UlpvV8sLE9kNAXT1x1sNkey1s8DJ3q0CmTeJAr6Z5SbNqsc lhVO04L7YKi1EYkqE4CjpgcGwN/lXpW7RFnsl7nBXUtz3/HCF/FIxt3gc7kv89Wn3QpX gMmQ== X-Gm-Message-State: AOPr4FVJ8qZGZxAoT6Le78j5KGdR32h6MntqDRn/J+xXfqc2QovUCZG8GZPRrrPneNpbwA== X-Received: by 10.157.41.33 with SMTP id d30mr14084139otb.179.1463293511753; Sat, 14 May 2016 23:25:11 -0700 (PDT) Received: from mail-oi0-f44.google.com (mail-oi0-f44.google.com. [209.85.218.44]) by smtp.gmail.com with ESMTPSA id t3sm8064949oih.7.2016.05.14.23.25.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 May 2016 23:25:11 -0700 (PDT) Received: by mail-oi0-f44.google.com with SMTP id v145so227247778oie.0; Sat, 14 May 2016 23:25:11 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.202.213.148 with SMTP id m142mr11366247oig.24.1463293511180; Sat, 14 May 2016 23:25:11 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.157.19.20 with HTTP; Sat, 14 May 2016 23:25:11 -0700 (PDT) In-Reply-To: <201605142322.u4ENMcxV083873@repo.freebsd.org> References: <201605142322.u4ENMcxV083873@repo.freebsd.org> Date: Sat, 14 May 2016 23:25:11 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r299778 - head/usr.sbin/bsnmpd/tools/libbsnmptools From: Conrad Meyer To: Garrett Cooper Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 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: Sun, 15 May 2016 06:25:19 -0000 On Sat, May 14, 2016 at 4:22 PM, Garrett Cooper wrote: > Author: ngie > Date: Sat May 14 23:22:38 2016 > New Revision: 299778 > URL: https://svnweb.freebsd.org/changeset/base/299778 > > Log: > Use a consistent errno save/restore pattern before running strtoul This is begging to be reduced to a subroutine for the common expression. Best, Conrad > > - 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. > > MFC after: 3 weeks > Sponsored by: EMC / Isilon Storage Division > > Modified: > head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c > > Modified: head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c > ============================================================================== > --- head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c Sat May 14 23:22:19 2016 (r299777) > +++ head/usr.sbin/bsnmpd/tools/libbsnmptools/bsnmptc.c Sat May 14 23:22:38 2016 (r299778) > @@ -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; >