diff options
author | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-06-19 18:43:28 +0000 |
---|---|---|
committer | Matthew Dempsky <matthew@cvs.openbsd.org> | 2012-06-19 18:43:28 +0000 |
commit | 0bceec318f7f0fafdb46cc4f9798bc8d4d1835b8 (patch) | |
tree | b0851dfbf572ae3349e6256f88497fb539c3b6f2 /usr.sbin/snmpd/mib.c | |
parent | 53045dc549ced1d3840daeab4776adf4b5147719 (diff) |
Use calloc() instead of malloc() for allocating the disk stats.
Requested by deraadt.
Diffstat (limited to 'usr.sbin/snmpd/mib.c')
-rw-r--r-- | usr.sbin/snmpd/mib.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c index 57d61b5ddcb..f01b3f2af28 100644 --- a/usr.sbin/snmpd/mib.c +++ b/usr.sbin/snmpd/mib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.c,v 1.54 2012/06/14 17:31:32 matthew Exp $ */ +/* $OpenBSD: mib.c,v 1.55 2012/06/19 18:43:27 matthew Exp $ */ /* * Copyright (c) 2012 Joel Knight <joel@openbsd.org> @@ -3406,10 +3406,11 @@ mib_diskio(struct oid *oid, struct ber_oid *o, struct ber_element **elm) o->bo_id[OIDIDX_diskIOEntry] = idx; ber = ber_add_oid(ber, o); - len = diskcount * sizeof(*stats); - stats = malloc(len); + stats = calloc(diskcount, sizeof(*stats)); if (stats == NULL) return (-1); + /* We know len won't overflow, otherwise calloc() would have failed. */ + len = diskcount * sizeof(*stats); mib[1] = HW_DISKSTATS; if (sysctl(mib, sizeofa(mib), stats, &len, NULL, 0) == -1) { free(stats); |