From owner-svn-src-head@FreeBSD.ORG Fri Jun 27 18:58:22 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 92B59593; Fri, 27 Jun 2014 18:58:22 +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 7FDDA2057; Fri, 27 Jun 2014 18:58:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5RIwMfS045973; Fri, 27 Jun 2014 18:58:22 GMT (envelope-from loos@svn.freebsd.org) Received: (from loos@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5RIwMEr045972; Fri, 27 Jun 2014 18:58:22 GMT (envelope-from loos@svn.freebsd.org) Message-Id: <201406271858.s5RIwMEr045972@svn.freebsd.org> From: Luiz Otavio O Souza Date: Fri, 27 Jun 2014 18:58:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267971 - head/usr.sbin/bsnmpd/modules/snmp_lm75 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jun 2014 18:58:22 -0000 Author: loos Date: Fri Jun 27 18:58:22 2014 New Revision: 267971 URL: http://svnweb.freebsd.org/changeset/base/267971 Log: Simplify the code a little bit using the update_sensor_sysctl() routine to retrieve the sensor temperature. This also avoid the overflow that could happen on sysctlnametomib(3) because the code was not checking the length of the mib array. CID: 1222504 Modified: head/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c Modified: head/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c ============================================================================== --- head/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c Fri Jun 27 18:51:19 2014 (r267970) +++ head/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c Fri Jun 27 18:58:22 2014 (r267971) @@ -172,7 +172,7 @@ sysctlgetnext(int *oid, int nlen, int *n } static int -update_sensor_sysctl(char *obuf, size_t *obuflen, int idx, const char *name) +update_sensor_sysctl(void *obuf, size_t *obuflen, int idx, const char *name) { char buf[LM75BUF]; int mib[5]; @@ -213,22 +213,18 @@ update_sensor(struct lm75_snmp_sensor *s } static int -add_sensor(char *buf, size_t nlen) +add_sensor(char *buf) { - int idx, mib[5], temp; + int idx, temp; size_t len; struct lm75_snmp_sensor *sensor; if (sscanf(buf, "dev.lm75.%d.temperature", &idx) != 1) return (-1); - /* Fill out the mib information. */ - if (sysctlnametomib(buf, mib, &nlen) == -1) - return (-1); - /* Read the sensor temperature. */ len = sizeof(temp); - if (sysctl(mib, nlen, &temp, &len, NULL, 0) == -1) + if (update_sensor_sysctl(&temp, &len, idx, "temperature") != 0) return (-1); /* Add the sensor data to the table. */ @@ -326,7 +322,7 @@ update_sensors(void) continue; if (strstr(buf, "temperature")) - if (add_sensor(buf, len) != 0) { + if (add_sensor(buf) != 0) { free(oid); return (-1); }