Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous snmp walk code incorrectly handles reaching end of mib view. #1925

Closed
sigmunau opened this issue Apr 26, 2019 · 1 comment · Fixed by #2489
Closed

Synchronous snmp walk code incorrectly handles reaching end of mib view. #1925

sigmunau opened this issue Apr 26, 2019 · 1 comment · Fixed by #2489
Assignees
Labels

Comments

@sigmunau
Copy link
Contributor

Upon reaching end of mib view the code should return the data found so far, but in stead it raises an exception. This happens both in bulkwalk and walk functions. When using SNMP v1 NoSuchObjectError is raised, with SNMP v2 EndOfMibViewError is raised.

The following diff "fixes" the problem for normal walk.

diff --git a/python/nav/Snmp/pynetsnmp.py b/python/nav/Snmp/pynetsnmp.py
index ef64c1150..9c1045111 100644
--- a/python/nav/Snmp/pynetsnmp.py
+++ b/python/nav/Snmp/pynetsnmp.py
@@ -171,7 +171,10 @@ class Snmp(object):
         current_oid = root_oid
 
         while 1:
-            response = self.handle.sgetnext(current_oid)
+            try:
+                response = self.handle.sgetnext(current_oid)
+            except (EndOfMibViewError, NoSuchObjectError):
+                break
             if response is None:
                 break
             response_oid, value = list(response.items())[0]

Assessing the correctness of this change and making a matching fix for bulkwalk needs to be done by someone else

@lunkwill42 lunkwill42 self-assigned this May 16, 2019
@lunkwill42 lunkwill42 added AD Related to Microsoft Active Directory bug and removed AD Related to Microsoft Active Directory labels May 16, 2019
@lunkwill42
Copy link
Member

lunkwill42 commented Jul 25, 2022

Using the snmpsim fixture, it should be trivial to at least produce an integration test that reproduces this bug in an automated fashion. That would be the first step in actually implementing the proposed fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants