1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 17:45:09 +00:00

ICMP: Check that incoming ICMP echo requests are large enough

Otherwise, just ignore them.
This commit is contained in:
Andreas Kling 2020-10-20 17:53:11 +02:00
parent 0af2795662
commit ce6ef54337

View file

@ -276,6 +276,10 @@ void handle_icmp(const EthernetFrameHeader& eth, const IPv4Packet& ipv4_packet,
auto& request = reinterpret_cast<const ICMPEchoPacket&>(icmp_header);
klog() << "handle_icmp: EchoRequest from " << ipv4_packet.source().to_string().characters() << ": id=" << (u16)request.identifier << ", seq=" << (u16)request.sequence_number;
size_t icmp_packet_size = ipv4_packet.payload_size();
if (icmp_packet_size < sizeof(ICMPEchoPacket)) {
klog() << "handle_icmp: EchoRequest packet is too small, ignoring.";
return;
}
auto buffer = ByteBuffer::create_zeroed(icmp_packet_size);
auto& response = *(ICMPEchoPacket*)buffer.data();
response.header.set_type(ICMPType::EchoReply);