Skip to content

Fix scalar values in SNMP set requests#15

Merged
bluecmd merged 1 commit into
bluecmd:masterfrom
SoundGoof:fix/issue-6-set-values
Jul 24, 2026
Merged

Fix scalar values in SNMP set requests#15
bluecmd merged 1 commit into
bluecmd:masterfrom
SoundGoof:fix/issue-6-set-values

Conversation

@SoundGoof

@SoundGoof SoundGoof commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #6 by allowing SNMP SET requests to accept canonical Python scalar values instead of requiring every value to be a bytes object.

The native extension now:

  • Preserves bytes values without modification, including binary OCTET STRING data.
  • Converts integers, strings, and other non-byte values using their canonical str() representation.
  • Keeps the Python object containing the converted value alive while constructing the SNMP PDU.
  • Propagates conversion errors directly instead of returning a secondary SystemError.

Root Cause

Varbind.val preserves its original Python type, but the SET implementation passed every value directly to PyBytes_AsStringAndSize().

This worked for bytes, but rejected integers, Python strings, and other scalar values before the SNMP request could be constructed.

The conversion helper now distinguishes between byte and non-byte values:

  • bytes values are passed through unchanged.
  • Other values are converted with str() and encoded through Python's UTF-8 representation.
  • The resulting Python object remains referenced until Net-SNMP has copied the value into the PDU.

Testing

The system tests run against a private Ubuntu snmpd instance.

Coverage includes:

  • Real SET→GET round trips for INTEGER values supplied as Python integers, strings, and byte strings.
  • Real SET→GET round trips for textual OCTET STRING values supplied as Python strings and byte strings.
  • A writable pass_persist INTEGER scalar, used because Ubuntu's packaged agent does not expose a suitable writable INTEGER object.
  • Packet-level verification that binary OCTET STRING values containing embedded NUL and non-UTF-8 bytes are preserved in the emitted BER payload.
  • Existing SNMPv1, SNMPv2c, and SNMPv3 system tests.

Results:

  • All 45 system tests pass normally.
  • All 45 system tests pass under Valgrind.
  • Valgrind reports 0 errors.
  • Valgrind reports no definitely, indirectly, or possibly lost memory.

@SoundGoof
SoundGoof force-pushed the fix/issue-6-set-values branch from 06b975f to 718a4ff Compare July 23, 2026 22:47
@SoundGoof
SoundGoof requested a review from bluecmd July 23, 2026 22:53
@bluecmd
bluecmd merged commit fce5ddd into bluecmd:master Jul 24, 2026
4 checks passed
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.

Trying to use any value in a Varbind results in an exception being thrown when attempting to set

2 participants