summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsnmpd
diff options
context:
space:
mode:
authorloos <loos@FreeBSD.org>2014-06-27 18:58:22 +0000
committerloos <loos@FreeBSD.org>2014-06-27 18:58:22 +0000
commitb63650e110bb06722e890fc98404a38cb5888340 (patch)
tree099474c527f63587c9ca92dc8477409f2659d8ad /usr.sbin/bsnmpd
parent534f953696e811ad5ed12ff0cea52668ff6ef85e (diff)
downloadFreeBSD-src-b63650e110bb06722e890fc98404a38cb5888340.zip
FreeBSD-src-b63650e110bb06722e890fc98404a38cb5888340.tar.gz
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
Diffstat (limited to 'usr.sbin/bsnmpd')
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_lm75/snmp_lm75.c14
1 files changed, 5 insertions, 9 deletions
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);
}
OpenPOWER on IntegriCloud