Skip to content

Commit

Permalink
Merge pull request #1409 from p-l-/fix-radius
Browse files Browse the repository at this point in the history
Remove useless _RADIUSAttrPacketListField class
  • Loading branch information
guedou committed May 11, 2018
2 parents 0e9c8eb + 0d7ae2b commit 905c80d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 31 deletions.
5 changes: 4 additions & 1 deletion scapy/layers/eap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ShortField, IntField, XIntField, ByteEnumField, StrLenField, XStrField,\
XStrLenField, XStrFixedLenField, LenField, FieldLenField, PacketField,\
PacketListField, ConditionalField, PadField
from scapy.packet import Packet, bind_layers
from scapy.packet import Packet, Padding, bind_layers
from scapy.layers.l2 import SourceMACField, Ether, CookedLinux, GRE, SNAP
from scapy.utils import issubtype
from scapy.config import conf
Expand Down Expand Up @@ -279,6 +279,9 @@ def post_build(self, p, pay):
p = p[:2] + chb((l >> 8) & 0xff) + chb(l & 0xff) + p[4:]
return p + pay

def guess_payload_class(self, _):
return Padding


class EAP_MD5(EAP):
"""
Expand Down
36 changes: 6 additions & 30 deletions scapy/layers/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
"""

import struct
import logging
import hashlib
import hmac
from scapy.compat import *
from scapy.packet import Packet, bind_layers
from scapy.compat import orb, raw
from scapy.packet import Packet, Padding, bind_layers
from scapy.fields import ByteField, ByteEnumField, IntField, StrLenField,\
XStrLenField, XStrFixedLenField, FieldLenField, PacketField,\
PacketListField, IPField, MultiEnumField
Expand Down Expand Up @@ -278,6 +277,9 @@ def post_build(self, p, pay):
p = p[:1] + struct.pack("!B", length) + p[2:]
return p

def guess_payload_class(self, _):
return Padding


class _SpecificRadiusAttr(RadiusAttribute):
"""
Expand Down Expand Up @@ -1055,32 +1057,6 @@ class RadiusAttr_Vendor_Specific(RadiusAttribute):
]


class _RADIUSAttrPacketListField(PacketListField):
"""
PacketListField handling a list of RADIUS attributes.
"""

def getfield(self, pkt, s):
lst = []
length = None
ret = ""

if self.length_from is not None:
length = self.length_from(pkt)

if length is not None:
remain, ret = s[:length], s[length:]

while remain:
attr_len = orb(remain[1])
current = remain[:attr_len]
remain = remain[attr_len:]
packet = self.m2i(pkt, current)
lst.append(packet)

return remain + ret, lst


# See IANA RADIUS Packet Type Codes registry
_packet_codes = {
1: "Access-Request",
Expand Down Expand Up @@ -1145,7 +1121,7 @@ class Radius(Packet):
adjust=lambda pkt, x: len(pkt.attributes) + 20
),
XStrFixedLenField("authenticator", "", 16),
_RADIUSAttrPacketListField(
PacketListField(
"attributes",
[],
RadiusAttribute,
Expand Down
4 changes: 4 additions & 0 deletions test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -8877,6 +8877,10 @@ l = PacketList(p)
s = l.sessions() # Crashed on commit: e42ecdc54556c4852ca06b1a6da6c1ccbf3f522e
assert len(s) == 1

= Issue GH#1407
s = b"Z\xa5\xaaUZ\xa5\xaaU\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe9\xc5\x00\x00\x14'\x02\x00\x00\x001\x9a\xe44\xea4"
isinstance(Radius(s), Radius)


############
############
Expand Down

0 comments on commit 905c80d

Please sign in to comment.