Skip to content

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.

twschum added 3 commits April 5, 2019 16:09
======================================================================
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
@twschum twschum marked this pull request as ready for review April 8, 2019 14:12
@GIC-de GIC-de force-pushed the master branch 2 times, most recently from f028133 to 5300091 Compare July 13, 2022 12:23
@GIC-de
Copy link
Collaborator

GIC-de commented Jul 24, 2024

Please rebase and resolve conflicts!

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.

2 participants