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

MIB with OCTET STRING DEFVAL ''H doesn't validate on load #336

Open
clarsen opened this issue Jan 9, 2020 · 1 comment
Open

MIB with OCTET STRING DEFVAL ''H doesn't validate on load #336

clarsen opened this issue Jan 9, 2020 · 1 comment

Comments

@clarsen
Copy link

clarsen commented Jan 9, 2020

Using pysnmp 4.4.9

Example:
from MIB http://mibs.snmplabs.com/asn1/IEEE8023-LAG-MIB

dot3adAggPartnerAdminPortAlgorithm OBJECT-TYPE
    SYNTAX      OCTET STRING (SIZE (4))
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION
        "This object identifies the value for the algorithm of the
        Partner System, assigned by administrator or System policy
        for use when the Partner's information is unknown. Table 6-4
        provides the IEEE 802.1 OUI (00-80-C2) Port Algorithm
        encodings. Its default value is set to NULL. A SEQUENCE OF
        OCTETS consisting of a 3-octet OUI or CID and one following
        octet."
    REFERENCE
        "7.3.1.1.34"
    DEFVAL  { ''H }
    ::= { dot3adAggXEntry 22 }

translates to:

dot3adAggPartnerAdminPortAlgorithm = MibTableColumn((1, 2, 840, 10006, 300, 43, 1, 1, 3, 1, 22),
    OctetString().subtype(subtypeSpec=ValueSizeConstraint(4,4))
                 .setFixedLength(4)
                 .clone(hexValue=""))
  .setMaxAccess("readwrite")

which on load via pysnmp.hlapi.ObjectIdentity gives:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 32, in __call__
    self._testValue(value, idx)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 298, in _testValue
    raise error.ValueConstraintError(value)
pyasn1.type.error.ValueConstraintError: b''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 32, in __call__
    self._testValue(value, idx)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 643, in _testValue
    constraint(value, idx)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 36, in __call__
    '%s failed at: %r' % (self, sys.exc_info()[1])
pyasn1.type.error.ValueConstraintError: <ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b'')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 269, in __init__
    self.subtypeSpec(value)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 36, in __call__
    '%s failed at: %r' % (self, sys.exc_info()[1])
pyasn1.type.error.ValueConstraintError: <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 4, 4>> failed at: ValueConstraintError("<ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b'')")

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 344, in loadModule
    exec(codeObj, g)
  File "/home/mon/u0/ctlarsen/.pysnmp/mibs/IEEE8023-LAG-MIB.py", line 150, in <module>
    dot3adAggPartnerAdminPortAlgorithm = MibTableColumn((1, 2, 840, 10006, 300, 43, 1, 1, 3, 1, 22), OctetString().subtype(subtypeSpec=ValueSizeConstraint(4, 4)).setFixedLength(4).clone(hexValue="")).setMaxAccess("readwrite")
  File "/usr/local/lib/python3.7/site-packages/pysnmp/proto/rfc1902.py", line 232, in clone
    return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 376, in clone
    return self.__class__(value, **initializers)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/univ.py", line 837, in __init__
    base.SimpleAsn1Type.__init__(self, value, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 273, in __init__
    raise exType('%s at %s' % (exValue, self.__class__.__name__))
pyasn1.type.error.ValueConstraintError: <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 4, 4>> failed at: ValueConstraintError("<ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b'')") at OctetString

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "check_lacp2.py", line 59, in <module>
    ).addAsn1MibSource(MIB_SOURCES)
  File "/usr/local/lib/python3.7/site-packages/pysnmp/hlapi/asyncore/sync/cmdgen.py", line 111, in getCmd
    lookupMib=options.get('lookupMib', True)))
  File "/usr/local/lib/python3.7/site-packages/pysnmp/hlapi/asyncore/cmdgen.py", line 130, in getCmd
    vbProcessor.makeVarBinds(snmpEngine, varBinds), __cbFun,
  File "/usr/local/lib/python3.7/site-packages/pysnmp/hlapi/varbinds.py", line 39, in makeVarBinds
    __varBinds.append(varBind.resolveWithMib(mibViewController))
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/rfc1902.py", line 847, in resolveWithMib
    self.__args[0].resolveWithMib(mibViewController)
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/rfc1902.py", line 481, in resolveWithMib
    self.__modName, self.__symName
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 423, in importSymbols
    self.loadModules(modName, **userCtx)
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 383, in loadModules
    self.loadModule(modName, **userCtx)
  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 349, in loadModule
    'MIB module \'%s\' load error: %s' % (modPath, traceback.format_exception(*sys.exc_info()))
pysnmp.smi.error.MibLoadError: MIB module '/home/mon/u0/ctlarsen/.pysnmp/mibs/IEEE8023-LAG-MIB/home/mon/u0/ctlarsen/.pysnmp/mibs/IEEE8023-LAG-MIB.py' load error: ['Traceback (most recent call last):\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 32, in __call__\n    self._testValue(value, idx)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 298, in _testValue\n    raise error.ValueConstraintError(value)\n', "pyasn1.type.error.ValueConstraintError: b''\n", '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 32, in __call__\n    self._testValue(value, idx)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 643, in _testValue\n    constraint(value, idx)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 36, in __call__\n    \'%s failed at: %r\' % (self, sys.exc_info()[1])\n', "pyasn1.type.error.ValueConstraintError: <ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b'')\n", '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 269, in __init__\n    self.subtypeSpec(value)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/constraint.py", line 36, in __call__\n    \'%s failed at: %r\' % (self, sys.exc_info()[1])\n', 'pyasn1.type.error.ValueConstraintError: <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 4, 4>> failed at: ValueConstraintError("<ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b\'\')")\n', '\nDuring handling of the above exception, another exception occurred:\n\n', 'Traceback (most recent call last):\n', '  File "/usr/local/lib/python3.7/site-packages/pysnmp/smi/builder.py", line 344, in loadModule\n    exec(codeObj, g)\n', '  File "/home/mon/u0/ctlarsen/.pysnmp/mibs/IEEE8023-LAG-MIB.py", line 150, in <module>\n    dot3adAggPartnerAdminPortAlgorithm = MibTableColumn((1, 2, 840, 10006, 300, 43, 1, 1, 3, 1, 22), OctetString().subtype(subtypeSpec=ValueSizeConstraint(4, 4)).setFixedLength(4).clone(hexValue="")).setMaxAccess("readwrite")\n', '  File "/usr/local/lib/python3.7/site-packages/pysnmp/proto/rfc1902.py", line 232, in clone\n    return univ.OctetString.clone(self, *args, **kwargs).setFixedLength(self.getFixedLength())\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 376, in clone\n    return self.__class__(value, **initializers)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/univ.py", line 837, in __init__\n    base.SimpleAsn1Type.__init__(self, value, **kwargs)\n', '  File "/usr/local/lib/python3.7/site-packages/pyasn1/type/base.py", line 273, in __init__\n    raise exType(\'%s at %s\' % (exValue, self.__class__.__name__))\n', 'pyasn1.type.error.ValueConstraintError: <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 4, 4>> failed at: ValueConstraintError("<ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b\'\')") at OctetString\n']caused by <class 'pyasn1.type.error.ValueConstraintError'>: <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 4, 4>> failed at: ValueConstraintError("<ValueSizeConstraint object, consts 4, 4> failed at: ValueConstraintError(b'')") at OctetString

I think due to the zero length default hexValue which should be 4 bytes by the constraint.
FWIW, changing the MIB to be:

dot3adAggPartnerAdminPortAlgorithm OBJECT-TYPE
    SYNTAX      OCTET STRING (SIZE (4))
    MAX-ACCESS  read-write
    STATUS      current
    DESCRIPTION
        "This object identifies the value for the algorithm of the
        Partner System, assigned by administrator or System policy
        for use when the Partner's information is unknown. Table 6-4
        provides the IEEE 802.1 OUI (00-80-C2) Port Algorithm
        encodings. Its default value is set to NULL. A SEQUENCE OF
        OCTETS consisting of a 3-octet OUI or CID and one following
        octet."
    REFERENCE
        "7.3.1.1.34"
    DEFVAL  { '00000000'H }
    ::= { dot3adAggXEntry 22 }

eliminated the failure.

Maybe the MIB is incorrect, but maybe some special-casing of empty default values since there may be many MIBS like this?

@lextm
Copy link

lextm commented Feb 19, 2025

Should have been resolved by lextudio/pysmi#3 which is shipped in pysmi 1.5.10+.

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

No branches or pull requests

2 participants