mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
LibDNS: Make DNS packet parsing fallible
Previously, a DNS packet containing an invalid name would be returned with an empty name. With this change, an error is returned if any error is encountered during parsing.
This commit is contained in:
parent
95d62822bf
commit
1793f51bc6
8 changed files with 29 additions and 40 deletions
|
@ -56,13 +56,7 @@ MulticastDNS::MulticastDNS(Core::EventReceiver* parent)
|
|||
ErrorOr<void> MulticastDNS::handle_packet()
|
||||
{
|
||||
auto buffer = TRY(receive(1024));
|
||||
auto optional_packet = Packet::from_raw_packet(buffer);
|
||||
if (!optional_packet.has_value()) {
|
||||
dbgln("Got an invalid mDNS packet");
|
||||
return {};
|
||||
}
|
||||
auto& packet = optional_packet.value();
|
||||
|
||||
auto packet = TRY(Packet::from_raw_packet(buffer));
|
||||
if (packet.is_query())
|
||||
handle_query(packet);
|
||||
return {};
|
||||
|
@ -175,12 +169,12 @@ ErrorOr<Vector<Answer>> MulticastDNS::lookup(Name const& name, RecordType record
|
|||
auto buffer = TRY(receive(1024));
|
||||
if (buffer.is_empty())
|
||||
return Vector<Answer> {};
|
||||
auto optional_packet = Packet::from_raw_packet(buffer);
|
||||
if (!optional_packet.has_value()) {
|
||||
dbgln("Got an invalid mDNS packet");
|
||||
auto packet_or_error = Packet::from_raw_packet(buffer);
|
||||
if (packet_or_error.is_error()) {
|
||||
dbgln("Got an invalid mDNS packet: {}", packet_or_error.release_error());
|
||||
continue;
|
||||
}
|
||||
auto& packet = optional_packet.value();
|
||||
auto packet = packet_or_error.release_value();
|
||||
|
||||
if (packet.is_query())
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue