From owner-svn-src-stable-10@freebsd.org Sat Jan 7 09:09:56 2017 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 40DBECA3EEE; Sat, 7 Jan 2017 09:09:56 +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 EA7A5163D; Sat, 7 Jan 2017 09:09:55 +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 v0799tdx090581; Sat, 7 Jan 2017 09:09:55 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v0799tD0090580; Sat, 7 Jan 2017 09:09:55 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201701070909.v0799tD0090580@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Sat, 7 Jan 2017 09:09:55 +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: r311603 - stable/10/contrib/bsnmp/lib 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.23 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: Sat, 07 Jan 2017 09:09:56 -0000 Author: ngie Date: Sat Jan 7 09:09:54 2017 New Revision: 311603 URL: https://svnweb.freebsd.org/changeset/base/311603 Log: MFC r310501: Be more strict about IpAddress type in snmp_value_parse(..) - Use inet_pton with AF_INET instead of doing longhand with sscanf. - Use gethostbyname2 with AF_INET to ensure that the hostname isn't accidentally parsed with another address family, e.g. AF_INET6. NB: IpAddress per RFC-2578 is IPv4 only. Work is in progress to add the InetAddress type and friends documented in RFC-4001 and elsewhere (which supports IPv4, IPv6, and more). Modified: stable/10/contrib/bsnmp/lib/snmp.c Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/bsnmp/lib/snmp.c ============================================================================== --- stable/10/contrib/bsnmp/lib/snmp.c Sat Jan 7 09:07:12 2017 (r311602) +++ stable/10/contrib/bsnmp/lib/snmp.c Sat Jan 7 09:09:54 2017 (r311603) @@ -51,6 +51,8 @@ #elif defined(HAVE_INTTYPES_H) #include #endif +#include +#include #include "asn1.h" #include "snmp.h" @@ -1384,29 +1386,16 @@ snmp_value_parse(const char *str, enum s case SNMP_SYNTAX_IPADDRESS: { struct hostent *he; - u_long ip[4]; - int n; - if (sscanf(str, "%lu.%lu.%lu.%lu%n", &ip[0], &ip[1], &ip[2], - &ip[3], &n) == 4 && (size_t)n == strlen(str) && - ip[0] <= 0xff && ip[1] <= 0xff && - ip[2] <= 0xff && ip[3] <= 0xff) { - v->ipaddress[0] = (u_char)ip[0]; - v->ipaddress[1] = (u_char)ip[1]; - v->ipaddress[2] = (u_char)ip[2]; - v->ipaddress[3] = (u_char)ip[3]; + if (inet_pton(AF_INET, str, &v->ipaddress) == 1) return (0); - } - - if ((he = gethostbyname(str)) == NULL) + if ((he = gethostbyname2(str, AF_INET)) == NULL) return (-1); if (he->h_addrtype != AF_INET) return (-1); - v->ipaddress[0] = he->h_addr[0]; - v->ipaddress[1] = he->h_addr[1]; - v->ipaddress[2] = he->h_addr[2]; - v->ipaddress[3] = he->h_addr[3]; + memcpy(v->ipaddress, he->h_addr, sizeof(v->ipaddress)); + return (0); }