Skip to content

Prevent crashes on bare Varbind arguments - #17

Merged
SoundGoof merged 1 commit into
bluecmd:masterfrom
SoundGoof:fix/issue-5-bare-varbind-crash
Jul 23, 2026
Merged

Prevent crashes on bare Varbind arguments#17
SoundGoof merged 1 commit into
bluecmd:masterfrom
SoundGoof:fix/issue-5-bare-varbind-crash

Conversation

@SoundGoof

Copy link
Copy Markdown
Collaborator

Summary

Fixes #5 by preventing interpreter crashes when a bare Varbind is passed to session methods that require a VarList.

Invalid arguments now produce direct Python exceptions instead of segmentation faults or secondary SystemError exceptions.

Root Cause

The native extension called PyObject_GetIter() but did not check whether iterator creation succeeded.

When a bare, non-iterable Varbind was supplied, iterator creation returned NULL and set a Python exception. Several methods then passed the null pointer to another API or decremented its reference count, causing a segmentation fault.

Other methods returned a value while an exception was still active, which Python reported as a SystemError.

Changes

  • Check that iterator acquisition succeeds before using or releasing the iterator.
  • Return NULL from native methods when a Python exception is active.
  • Initialize cleanup references before use.
  • Prevent double decrements on response-processing error paths.
  • Apply the safety checks to:
    • get
    • getnext
    • set
    • walk
    • getbulk
  • Add regression coverage for all five methods.

Behavior

Before this change:

  • get, getnext, and set terminated the interpreter with SIGSEGV.
  • walk and getbulk raised SystemError.

After this change:

  • get, getnext, and set raise TypeError.
  • walk and getbulk raise AttributeError.

Testing

  • Built the native extension on Fedora 43 with Python 3.14 and Net-SNMP 5.9.4.
  • Ran the focused five-method regression test.
  • Verified each method in an isolated subprocess.
  • Confirmed no method crashes the interpreter.
  • Confirmed the native C file has no diagnostics.
  • Confirmed the patch passes the whitespace check.

@SoundGoof
SoundGoof force-pushed the fix/issue-5-bare-varbind-crash branch from 5e8e829 to ef13d30 Compare July 23, 2026 21:12
@SoundGoof
SoundGoof requested a review from bluecmd July 23, 2026 21:22
@SoundGoof
SoundGoof merged commit 14be639 into bluecmd:master Jul 23, 2026
4 checks passed
@SoundGoof
SoundGoof deleted the fix/issue-5-bare-varbind-crash branch July 23, 2026 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segfault when trying to set/get with a bare Varbind

2 participants