Skip to content

IP.fragment_by_size() crashes on IP packets without payload (len(None)) #2094

@L1-0

Description

@L1-0

Configuration

impacket version: master (source)
Python version: 3.11.2
Target OS: Linux x86_64

Debug Output With Command String

python -c "import sys,traceback; sys.path.insert(0,'./'); from impacket.ImpactPacket import IP; ip=IP(); ip.fragment_by_size(8)"

Observed output:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "./impacket/ImpactPacket.py", line 1028, in fragment_by_size
    data_len = len(self.get_data_as_string())
TypeError: object of type 'NoneType' has no len()

PCAP

N/A

Additional context

get_data_as_string() returns None when there is no child/payload. fragment_by_size() calls len() on it unconditionally.

Suggested fix:

data = self.get_data_as_string()
if not data:
    return [self]
data_len = len(data)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions