Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Jun 2014 18:58:22 +0000 (UTC)
From:      Luiz Otavio O Souza <loos@FreeBSD.org>
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
Message-ID:  <201406271858.s5RIwMEr045972@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);
 			}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406271858.s5RIwMEr045972>