vincentbernat / snimpy

interactive SNMP tool with Python
http://snimpy.readthedocs.org/
185 stars 44 forks source link

SNMP Community Strings greater than 32 characters crash #93

Closed sergitron closed 4 years ago

sergitron commented 4 years ago

I have seen an issue with long community strings(>32 chars) causing snimpy to puke with an error like this(I replaced community string with X's): “ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(ConstraintsIntersection(), ValueSizeConstraint(0, 65535)), ValueSizeConstraint(0, 255)), ValueSizeConstraint(1, 32)) failed at: ValueConstraintError("ValueSizeConstraint(1, 32) failed at: ValueConstraintError('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',)",) at SnmpAdminString”

This is caused by the assumption in snimpy to use the same community string as both the community data and the community index into pysnmp in the CommunityData constructor. The Community Index must be less than 32 characters. My workaround is to slice the string to less than 32 characters in the Community Index.

In the existing snmp module, this is the offending code:

Put authentication stuff in self._auth

    if version in [1, 2]:
        self._auth = cmdgen.CommunityData(
            community, community, version - 1)

What I have done for a workaround is:

Put authentication stuff in self._auth

    if version in [1, 2]:
        self._auth = cmdgen.CommunityData(
            community[0:31], community, version - 1)

Does this seem like a reasonable fix that I could do a PR for or would something else be better ?

Thanks, Sergio

vincentbernat commented 4 years ago

Yes, this is fine. We could even just use an arbitrary string from what I understand. Please do a PR with whatever you think is best.

vincentbernat commented 4 years ago

Fixed in #94