troglobit / mini-snmpd

A minimal SNMP agent implementation
https://troglobit.com/projects/mini-snmpd/
GNU General Public License v2.0
69 stars 36 forks source link

Encoding of Counter32-value can be invalid #8

Closed prauscher closed 7 years ago

prauscher commented 7 years ago

According to X.690, all Integers (which Counter32 is internally) must be transmitted signed. In the current implementation, a value of 33000 will be encoded as 0x80e8, which will be parsed as a signed int on the client, resulting in -32536 and failing with a ValueRangeConstraint (PySNMP) or Net-SNMP first expanding 0x80e8 to 0xffff80e8 (as it should contain 32 bits and the first bit indicates a negative value) and then parsing the value as unsigned int for no obvious reason, resulting in 4294934760. Therefore, mini-snmpd must encode values like 33000 with a leading zero-byte: 0x0080e8.