allthingssecurity commented on code in PR #27242:
URL: https://github.com/apache/camel/pull/27242#discussion_r4163571220
##########
components/camel-snmp/src/main/java/org/apache/camel/component/snmp/SnmpProducer.java:
##########
@@ -143,24 +144,34 @@ public void process(final Exchange exchange) throws
Exception {
while (matched) {
ResponseEvent responseEvent = snmp.send(this.pdu,
this.target);
if (responseEvent == null ||
responseEvent.getResponse() == null) {
- break;
+ throw new TimeoutException("SNMP Producer
Timeout");
}
PDU response = responseEvent.getResponse();
- String nextOid = null;
- List<? extends VariableBinding> variableBindings =
response.getVariableBindings();
- for (int i = 0; i < variableBindings.size(); i++) {
- VariableBinding variableBinding =
variableBindings.get(i);
- nextOid =
variableBinding.getOid().toDottedString();
- if (!nextOid.startsWith(oid.toDottedString())) {
+ if (response.getErrorStatus() == PDU.noSuchName) {
+ // SNMPv1 signals the end of the MIB view with
noSuchName
+ break;
+ }
+ if (response.getErrorStatus() != PDU.noError) {
+ throw new CamelExchangeException(
+ "SNMP walk of " + oid + " failed: " +
response.getErrorStatusText(), exchange);
+ }
+ OID requestedOid = this.pdu.get(0).getOid();
+ VariableBinding next = null;
+ for (VariableBinding variableBinding :
response.getVariableBindings()) {
+ // compare the OIDs, not their strings:
1.3.6.1.4.1.20 is not in the subtree of 1.3.6.1.4.1.2
+ if (!variableBinding.getOid().startsWith(oid)) {
matched = false;
break;
}
+ next = variableBinding;
}
- if (!matched) {
+ // endOfMibView (SNMPv2c/v3) ends the walk, and so
does an OID that does not increase,
+ // otherwise the same OID would be requested again
forever
+ if (!matched || next == null || next.isException() ||
next.getOid().compareTo(requestedOid) <= 0) {
Review Comment:
Agreed, done in 0bc71e557301. An OID inside the subtree that does not
increase now fails the exchange with `CamelExchangeException` (`SNMP walk of
<oid> failed: OID not increasing: <requested> >= <returned>`). An
`endOfMibView` value still ends the walk normally, because that check comes
first. `WalkOIDEndTest.testWalkWithOidNotIncreasingFails` covers it, and the
upgrade note mentions it. All 21 camel-snmp tests pass.
On the shared `this.pdu`: agreed, that is a separate follow-up.
_Claude Code on behalf of allthingssecurity_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]