From d6014c886997e56e923541c0bae07cd1b69155c6 Mon Sep 17 00:00:00 2001 From: sideshowbarker Date: Wed, 17 Jun 2026 16:21:10 +0900 Subject: [PATCH] LibDNS: Serialize answer and authority records in Message::to_raw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Message::to_raw could only encode queries: It asserted the answer and authority counts were zero and never wrote those. So, a response — which carries answers — couldn’t be serialized at all. Fix: Write the answer and authority records as well — alongside the existing question and additional sections, and using the existing ResourceRecord::to_raw. Then drop the query-only assertions. The order matches the wire format: question, answer, authority, additional. --- Libraries/LibDNS/Message.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Libraries/LibDNS/Message.cpp b/Libraries/LibDNS/Message.cpp index d6d1e4ac1c..1b94967753 100644 --- a/Libraries/LibDNS/Message.cpp +++ b/Libraries/LibDNS/Message.cpp @@ -101,11 +101,6 @@ ErrorOr Message::from_raw(ParseContext& ctx) ErrorOr Message::to_raw(ByteBuffer& out) const { - // NOTE: This is minimally implemented to allow for sending queries, - // server-side responses are not implemented yet. - VERIFY(header.answer_count == 0); - VERIFY(header.authority_count == 0); - auto start_size = out.size(); auto header_bytes = TRY(out.get_bytes_for_writing(sizeof(Header))); @@ -114,6 +109,12 @@ ErrorOr Message::to_raw(ByteBuffer& out) const for (size_t i = 0; i < header.question_count; i++) TRY(questions[i].to_raw(out)); + for (size_t i = 0; i < header.answer_count; i++) + TRY(answers[i].to_raw(out)); + + for (size_t i = 0; i < header.authority_count; i++) + TRY(authorities[i].to_raw(out)); + for (size_t i = 0; i < header.additional_count; i++) TRY(additional_records[i].to_raw(out));