aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/bsnmpd
diff options
context:
space:
mode:
authorEnji Cooper <ngie@FreeBSD.org>2017-01-01 00:23:43 +0000
committerEnji Cooper <ngie@FreeBSD.org>2017-01-01 00:23:43 +0000
commit570afb920cfcaab3dd2995d15c09de217635cf9a (patch)
tree3abe7e5025a8ddc0d334f0135ead8062b33e40f4 /usr.sbin/bsnmpd
parent1cc49661ecb72b52f7c5e6986d553929041b8bee (diff)
downloadsrc-570afb920cfcaab3dd2995d15c09de217635cf9a.tar.gz
src-570afb920cfcaab3dd2995d15c09de217635cf9a.zip
Call snmp_pdu_free on req/resp with a consistent, correct pattern
- snmp_pdu_free should be called before snmp_pdu_create is called again - snmp_pdu_free should be called on the resp to snmp_dialog when successful Tested with the following bsnmp commands: % export SNMPUSER=bsnmp SNMPPASSWD=bsnmptest % SNMP_ARGS="-A proto=sha -C context='' -K -P proto=des -v 3 -r 0" % bsnmpset $SNMP_ARGS sysLocation="MyAgent" % bsnmpget $SNMP_ARGS sysLocation % bsnmpwalk $SNMP_ARGS MFC after: 12 days X-MFC with: r310729, r310892, r310894
Notes
Notes: svn path=/head/; revision=310989
Diffstat (limited to 'usr.sbin/bsnmpd')
-rw-r--r--usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c
index 0f74eb2ae768..752ddc0f0399 100644
--- a/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c
+++ b/usr.sbin/bsnmpd/tools/bsnmptools/bsnmpget.c
@@ -400,13 +400,16 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx)
if (snmp_parse_resp(&resp, &req) >= 0) {
snmp_output_resp(snmptoolctx, &resp, NULL);
+ snmp_pdu_free(&resp);
break;
}
snmp_output_err_resp(snmptoolctx, &resp);
if (GET_PDUTYPE(snmptoolctx) == SNMP_PDU_GETBULK ||
- !ISSET_RETRY(snmptoolctx))
+ !ISSET_RETRY(snmptoolctx)) {
+ snmp_pdu_free(&resp);
break;
+ }
/*
* Loop through the object list and set object->error to the
@@ -414,8 +417,10 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx)
*/
if (snmp_object_seterror(snmptoolctx,
&(resp.bindings[resp.error_index - 1]),
- resp.error_status) <= 0)
+ resp.error_status) <= 0) {
+ snmp_pdu_free(&resp);
break;
+ }
fprintf(stderr, "Retrying...\n");
snmp_pdu_free(&resp);
@@ -423,7 +428,6 @@ snmptool_get(struct snmp_toolinfo *snmptoolctx)
}
snmp_pdu_free(&req);
- snmp_pdu_free(&resp);
return (0);
}
@@ -500,8 +504,10 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
outputs += rc;
- if ((u_int)rc < resp.nbindings)
+ if ((u_int)rc < resp.nbindings) {
+ snmp_pdu_free(&resp);
break;
+ }
snmpwalk_nextpdu_create(op,
&(resp.bindings[resp.nbindings - 1].var), &req);
@@ -515,10 +521,11 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
if (outputs == 0) {
snmpwalk_nextpdu_create(SNMP_PDU_GET, &root, &req);
if (snmp_dialog(&req, &resp) == SNMP_CODE_OK) {
- if (snmp_parse_resp(&resp,&req) < 0)
+ if (snmp_parse_resp(&resp, &req) < 0)
snmp_output_err_resp(snmptoolctx, &resp);
else
- snmp_output_resp(snmptoolctx, &(resp), NULL);
+ snmp_output_resp(snmptoolctx, &resp,
+ NULL);
snmp_pdu_free(&resp);
} else
warn("Snmp dialog");
@@ -534,7 +541,6 @@ snmptool_walk(struct snmp_toolinfo *snmptoolctx)
}
snmp_pdu_free(&req);
- snmp_pdu_free(&resp);
if (rc == 0)
return (0);
@@ -1094,25 +1100,29 @@ snmptool_set(struct snmp_toolinfo *snmptoolctx)
if (snmp_pdu_check(&req, &resp) > 0) {
if (GET_OUTPUT(snmptoolctx) != OUTPUT_QUIET)
snmp_output_resp(snmptoolctx, &resp, NULL);
+ snmp_pdu_free(&resp);
break;
}
snmp_output_err_resp(snmptoolctx, &resp);
- if (!ISSET_RETRY(snmptoolctx))
+ if (!ISSET_RETRY(snmptoolctx)) {
+ snmp_pdu_free(&resp);
break;
+ }
if (snmp_object_seterror(snmptoolctx,
&(resp.bindings[resp.error_index - 1]),
- resp.error_status) <= 0)
+ resp.error_status) <= 0) {
+ snmp_pdu_free(&resp);
break;
+ }
fprintf(stderr, "Retrying...\n");
snmp_pdu_free(&req);
- snmp_pdu_free(&resp);
snmp_pdu_create(&req, SNMP_PDU_SET);
}
- snmp_pdu_free(&resp);
+ snmp_pdu_free(&req);
return (0);
}