LibDNS: Serialize answer and authority records in Message::to_raw

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.
This commit is contained in:
sideshowbarker 2026-06-17 16:21:10 +09:00 committed by Alexander Kalenik
parent 61bba95948
commit d6014c8869

View file

@ -101,11 +101,6 @@ ErrorOr<Message> Message::from_raw(ParseContext& ctx)
ErrorOr<size_t> 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<size_t> 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));