From b63650e110bb06722e890fc98404a38cb5888340 Mon Sep 17 00:00:00 2001 From: loos Date: Fri, 27 Jun 2014 18:58:22 +0000 Subject: 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 --- usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'usr.sbin/bsnmpd') diff --git a/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c b/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c index 7935d97..1822f78 100644 --- a/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c +++ b/usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c @@ -172,7 +172,7 @@ sysctlgetnext(int *oid, int nlen, int *next, size_t *nextlen) } 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 *sensor, int idx) } 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); } -- cgit v1.1