summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/lib
diff options
context:
space:
mode:
authorngie <ngie@FreeBSD.org>2017-01-07 08:42:14 +0000
committerngie <ngie@FreeBSD.org>2017-01-07 08:42:14 +0000
commit974717b39caadd27410500e58680c44572921844 (patch)
tree8abd40bf4f4da55bf134f20cdc4ca36f39ee087f /contrib/bsnmp/lib
parentb6903072edd16b3e4bdb742fb6249a7c2430b4c0 (diff)
downloadFreeBSD-src-974717b39caadd27410500e58680c44572921844.zip
FreeBSD-src-974717b39caadd27410500e58680c44572921844.tar.gz
MFC r310931,r310942,r310988:
r310931: Use strdup in snmp_parse_server(..) when possible instead of malloc+strcpy This simplifies the code and mutes a Coverity warning about sc->cport being improperly allocated CID: 1018247 r310942: Unbreak the build by passing the string to strdup, not its length Pointyhat to: ngie r310988: snmp_discover_engine: fix up req/resp (PDU object) handling a bit - Call snmp_pdu_free on req and resp when done with the objects - Call snmp_pdu_free on req before calling snmp_pdu_create on it again
Diffstat (limited to 'contrib/bsnmp/lib')
-rw-r--r--contrib/bsnmp/lib/snmpclient.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/contrib/bsnmp/lib/snmpclient.c b/contrib/bsnmp/lib/snmpclient.c
index d2ce74a..61f3c6d 100644
--- a/contrib/bsnmp/lib/snmpclient.c
+++ b/contrib/bsnmp/lib/snmpclient.c
@@ -1793,12 +1793,14 @@ snmp_discover_engine(char *passwd)
return (0);
}
+ snmp_pdu_free(&req);
+
snmp_pdu_create(&req, SNMP_PDU_GET);
req.engine.engine_boots = 0;
req.engine.engine_time = 0;
if (snmp_dialog(&req, &resp) == -1)
- return (-1);
+ return (-1);
if (resp.version != req.version) {
seterr(&snmp_client, "wrong version");
@@ -1813,6 +1815,9 @@ snmp_discover_engine(char *passwd)
snmp_client.engine.engine_boots = resp.engine.engine_boots;
snmp_client.engine.engine_time = resp.engine.engine_time;
+ snmp_pdu_free(&req);
+ snmp_pdu_free(&resp);
+
return (0);
}
@@ -1937,20 +1942,18 @@ snmp_parse_server(struct snmp_client *sc, const char *str)
}
/* port */
free(sc->cport);
- if ((sc->cport = malloc(strlen(p + 1) + 1)) == NULL) {
+ if ((sc->cport = strdup(p + 1)) == NULL) {
seterr(sc, "%s", strerror(errno));
return (-1);
}
- strcpy(sc->cport, p + 1);
} else if (p > s) {
/* host */
free(sc->chost);
- if ((sc->chost = malloc(strlen(s) + 1)) == NULL) {
+ if ((sc->chost = strdup(s)) == NULL) {
seterr(sc, "%s", strerror(errno));
return (-1);
}
- strcpy(sc->chost, s);
}
return (0);
}
OpenPOWER on IntegriCloud