[PR #1842] [MERGED] FIX WIP: Zone Parser panics when hostname entry has a leading whitespace. #2649

Closed
opened 2026-03-16 11:00:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hickory-dns/hickory-dns/pull/1842
Author: @wuerges
Created: 11/28/2022
Status: Merged
Merged: 12/21/2022
Merged by: @bluejekyll

Base: mainHead: fix_zone_parse_panic


📝 Commits (2)

  • 34879c3 add test to show parser panic
  • 562d61b fix panic on record types and dns class parse when type has symbols

📊 Changes

3 files changed (+65 additions, -22 deletions)

View changed files

📝 crates/client/src/serialize/txt/zone.rs (+27 -0)
📝 crates/proto/src/rr/dns_class.rs (+31 -21)
📝 crates/proto/src/rr/record_type.rs (+7 -1)

📄 Description

Context:

https://github.com/bluejekyll/trust-dns/issues/1843
Zone parses panic when parsing a zone that contains a hostname with a leading whitespace, instead of resulting in an Err, when running in #cfg(debug).

Expected behavior

When parsing an invalid zone, we expected an Err, but instead trust-dns panics:

The faulty zone

$ORIGIN parsed.zone.origin.org.
 faulty-record-type 60 IN A 1.2.3.4

The error

---- serialize::txt::zone::tests::test_zone_parse stdout ----
thread 'serialize::txt::zone::tests::test_zone_parse' panicked at 'assertion failed: str.chars().all(|x| char::is_ascii_uppercase(&x))', crates/proto/src/rr/dns_class.rs:56:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Root cause:

The root cause of the error was a debug_assert call that assumed that after an to_ascii_uppercase, all characters turn into ascii uppercase letters.
The debug_assert failed because of characters that are not letters, such as the -.

When a line in the zone file starts with a whitespace, it does not represent a new hostname. It represents a record belonging to the previous line.

Therefore, the parser was not trying to parse the faulty-record-type as a hostname name.

The parser correctly tried to parse the faulty hostname as a DNSClass and then as a RecordType.

However, since the faulty-record-type contained an -, it panicked.

This PR:

  • adds a test to show a zone that when parsed, panics.
  • relaxes the debug assert causing the panic.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hickory-dns/hickory-dns/pull/1842 **Author:** [@wuerges](https://github.com/wuerges) **Created:** 11/28/2022 **Status:** ✅ Merged **Merged:** 12/21/2022 **Merged by:** [@bluejekyll](https://github.com/bluejekyll) **Base:** `main` ← **Head:** `fix_zone_parse_panic` --- ### 📝 Commits (2) - [`34879c3`](https://github.com/hickory-dns/hickory-dns/commit/34879c356a876d2a4826ad374a978eb1f71ba0af) add test to show parser panic - [`562d61b`](https://github.com/hickory-dns/hickory-dns/commit/562d61b634affae6e75c1afa2e3892ad5e1e5ab3) fix panic on record types and dns class parse when type has symbols ### 📊 Changes **3 files changed** (+65 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `crates/client/src/serialize/txt/zone.rs` (+27 -0) 📝 `crates/proto/src/rr/dns_class.rs` (+31 -21) 📝 `crates/proto/src/rr/record_type.rs` (+7 -1) </details> ### 📄 Description # Context: https://github.com/bluejekyll/trust-dns/issues/1843 Zone parses panic when parsing a zone that contains a hostname with a leading whitespace, instead of resulting in an Err, when running in `#cfg(debug)`. ## Expected behavior When parsing an invalid zone, we expected an Err, but instead trust-dns panics: > The faulty zone ``` $ORIGIN parsed.zone.origin.org. faulty-record-type 60 IN A 1.2.3.4 ``` > The error ``` ---- serialize::txt::zone::tests::test_zone_parse stdout ---- thread 'serialize::txt::zone::tests::test_zone_parse' panicked at 'assertion failed: str.chars().all(|x| char::is_ascii_uppercase(&x))', crates/proto/src/rr/dns_class.rs:56:9 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` # Root cause: The root cause of the error was a `debug_assert` call that assumed that after an `to_ascii_uppercase`, all characters turn into ascii uppercase letters. The `debug_assert` failed because of characters that are not letters, such as the `-`. When a line in the zone file starts with a whitespace, it does not represent a new hostname. It represents a record belonging to the previous line. Therefore, the parser was not trying to parse the `faulty-record-type` as a hostname name. The parser *correctly* tried to parse the faulty hostname as a `DNSClass` and then as a `RecordType`. However, since the `faulty-record-type` contained an `-`, it panicked. # This PR: - [x] adds a test to show a zone that when parsed, panics. - [x] relaxes the debug assert causing the panic. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-16 11:00:35 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#2649
No description provided.