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

Fix unknown attributes breaking packet init #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

twschum
Copy link

@twschum twschum commented Apr 5, 2019

The Problem

Reading a raw RADIUS packet fails if a dictfile is supplied and any attributes in the packet are not in the dictionary. A KeyError is raised because of the logic testing the attribute as a 'tlv' attribute which expects a valid attribute object to exist in the dictionary.

Adds a test that exposed this problem.

ERROR: testDecodePacketWithUnknownAttribute (tests.testPacket.PacketTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/testPacket.py", line 337, in testDecodePacketWithUnknownAttribute
    six.b('\x01\x02\x00\x1b1234567890123456\x09\x07value'))
  File "/Users/user/pyrad/pyrad/packet.py", line 415, in DecodePacket
    elif self.dict.attributes[self._DecodeKey(key)].type == 'tlv':
KeyError: 9

Why This Solution

Adds a function to test if an attribute is a TLV attribute, which is just good code reuse are three places in packet.py that test for a TLV attribute. This function simply returns False if the attribute does not exist.

Also added a larger test case with a dictfile that reflects actual RADIUS attributes according to IANA, and a realistic packet containing fields that first exposed this is error in a production implementation using pyrad.

======================================================================
ERROR: testDecodePacketWithUnknownAttribute (tests.testPacket.PacketTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "tests/testPacket.py", line 337, in testDecodePacketWithUnknownAttribute
    six.b('\x01\x02\x00\x1b1234567890123456\x09\x07value'))
  File "/Users/user/pyrad/pyrad/packet.py", line 415, in DecodePacket
    elif self.dict.attributes[self._DecodeKey(key)].type == 'tlv':
KeyError: 9
@GIC-de GIC-de force-pushed the master branch 2 times, most recently from f028133 to 5300091 Compare July 13, 2022 12:23
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.

None yet

1 participant