hickory-dns / resolv-conf

The /etc/resolv.conf file parser in rust
Apache License 2.0
27 stars 25 forks source link

fail parsing resolv.conf with escape sequence #38

Open JyJyJcr opened 2 days ago

JyJyJcr commented 2 days ago

Describe the bug /etc/resolv.conf with non-LDH escape sequence causes parse error.

To Reproduce

  1. add any domain containing non-LDH \-escape sequence to /etc/resolv.conf
  2. install something which uses hickory-resolver crate as the resolver
  3. execute it with system configuration = /etc/resolv.conf

Simplest example:

add space\032space.com into domain search list, then

cargo install hickory-util
resolve -s github.com

will fail with this error:

Error: ResolveError { kind: Io(Custom { kind: Other, error: "Error parsing resolv.conf: Malformed label: space\u{1a}space" }) }

Expected behavior

  1. the resolver should parse resolv.conf as vaild file
  2. if not, escape sequence should be unescaped as decimal escape

expected result of the example above:

1.

  Querying for github.com A from [system provided nameservers...]
  Success for query github.com IN A
      github.com. 51 IN A 20.27.177.113

2.

  Error: ResolveError { kind: Io(Custom { kind: Other, error: "Error parsing resolv.conf: Malformed label: space\u{20}space" }) }

System: 1.

Version: Crate: hickory-resolver Version: 0.24.1

Additional context when domain search list with non LDH characters provided, some DHCP client implementations use \-escape decimal sequences and put the escaped domains into /etc/resolv.conf:

This behavior corresponds with non-LDH escape defined in Section 2.1 of RFC 4343.

Strangely, ISC-DHCP use C-style octal escape sequence:

https://github.com/hickory-dns/hickory-dns/pull/330 seems following ISC-DHCP.