snmpd fix invalid error codes

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

snmpd fix invalid error codes

Martijn van Duren-5
mps_get{,next}req makes the false assumption that root is empty, but if
o_get fails there might be data in there. The following diff fixes the
issue reported earlier today for the failing mib.
.iso.org.dod.internet.mgmt.mib_2.interfaces.ifTable.ifEntry.ifInDiscards

Changes the snmp(1) output from:
$ snmp get -v2c -On -cpublic 127.0.0.1 ifInDiscards.2    
snmp: get: Undefined error: 0
to
$ snmp get -v2c -On -cpublic 127.0.0.1 ifInDiscards.2
.1.3.6.1.2.1.2.2.1.13.2 = No Such Object available on this agent at this OID

Also tested with getnext and bulkget.

OK?

martijn@

Index: mps.c
===================================================================
RCS file: /cvs/src/usr.sbin/snmpd/mps.c,v
retrieving revision 1.25
diff -u -p -r1.25 mps.c
--- mps.c 16 May 2019 05:00:00 -0000 1.25
+++ mps.c 13 Aug 2019 13:51:16 -0000
@@ -166,7 +166,11 @@ fail:
  return (-1);
 
  /* Set SNMPv2 extended error response. */
- elm = ber_add_oid(elm, o);
+ if (root->be_union.bv_sub != NULL) {
+ elm = ber_unlink_elements(root);
+ ber_free_elements(elm);
+ }
+ elm = ber_add_oid(root, o);
  elm = ber_add_null(elm);
  ber_set_header(elm, BER_CLASS_CONTEXT, error_type);
  return (0);
@@ -289,7 +293,11 @@ fail:
  return (-1);
 
  /* Set SNMPv2 extended error response. */
- ber = ber_add_oid(ber, o);
+ if (root->be_union.bv_sub != NULL) {
+ ber = ber_unlink_elements(root);
+ ber_free_elements(ber);
+ }
+ ber = ber_add_oid(root, o);
  ber = ber_add_null(ber);
  ber_set_header(ber, BER_CLASS_CONTEXT, error_type);
  return (0);