Skip to content

__str__ method is not safe #83

Closed
@elqver

Description

@elqver

This code results with segmentation fault

from typing import List

import netfilterqueue
from netfilterqueue import NetfilterQueue


packet_storage: List[netfilterqueue.Packet] = []


def print_packets():
    for packet in packet_storage:
        print(packet)


def handle_packet(packet: netfilterqueue.Packet):
    packet.retain()
    packet.accept()
    packet_storage.append(packet)
    print_packets()


q = NetfilterQueue()
q.bind(11, handle_packet)
q.run()

Looks like str method is not safe, because there is no check for NULL of self.payload:

    def __str__(self):
        cdef iphdr *hdr = <iphdr*>self.payload
        protocol = PROTOCOLS.get(hdr.protocol, "Unknown protocol")
        return "%s packet, %s bytes" % (protocol, self.payload_len)

Is this ok, can that be fixed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions