[GH-ISSUE #644] resolv.conf parsing fails when it contains a 'search …' line #260

Closed
opened 2026-03-07 23:05:39 +03:00 by kerem · 8 comments
Owner

Originally created by @Flakebi on GitHub (Dec 22, 2018).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/644

Describe the bug
AsyncResolver::from_system_conf fails if the resolv.conf file contains a line like this:

search Speedport_000

To Reproduce
Steps to reproduce the behavior:

  1. Add a line search Speedport_000 to /etc/resolv.conf
  2. Call AsyncResolver::from_system_conf()

Expected behavior
trust-dns works like a charm, as it does normally.

System:

  • OS: Arch Linux
  • Architecture: x86_64
  • Version: Latest (as of 2018-12-22)
  • rustc version: 1.33.0-nightly (96d1334e5 2018-12-14)

Version:
Crate: resolver
Version: 0.10.1

Additional context
My complete resolv.conf:

# Generated by NetworkManager
search Speedport_000
nameserver 192.168.2.1

Upper part of the backtrace:

Error parsing resolv.conf: ProtoError { inner: stack backtrace:
   0: failure::backtrace::internal::InternalBacktrace::new::ha50a9f67574157be (0x55ff97537442)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/backtrace/internal.rs:44
   1: failure::backtrace::Backtrace::new::h9119d83d8139bf81 (0x55ff975362bd)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/backtrace/mod.rs:111
   2: <failure::context::Context<D>>::new::hf6b8acbfc40686fd (0x55ff96c14e89)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/context.rs:84
   3: <trust_dns_proto::error::ProtoError as core::convert::From<trust_dns_proto::error::ProtoErrorKind>>::from::ha1512e07bde176b8 (0x55ff96bfd670)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/error.rs:235
   4: <T as core::convert::Into<U>>::into::hb745de55117c81d1 (0x55ff96bfd40a)
             at /rustc/96d1334e567237b1507cd277938e7ae2de75ff51/src/libcore/convert.rs:454
   5: <trust_dns_proto::error::ProtoError as core::convert::From<alloc::string::String>>::from::h754d31b80be50be3 (0x55ff96bfd7a2)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/error.rs:254
   6: <T as core::convert::Into<U>>::into::h54d7f9426f1d5d32 (0x55ff96c75410)
             at /rustc/96d1334e567237b1507cd277938e7ae2de75ff51/src/libcore/convert.rs:454
   7: trust_dns_proto::rr::domain::label::Label::from_utf8::h490451d14e858eaa (0x55ff96c1f3ba)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/label.rs:64
   8: <trust_dns_proto::rr::domain::name::LabelEncUtf8 as trust_dns_proto::rr::domain::name::LabelEnc>::to_label::hdc02f939975cf2a8 (0x55ff96c6d144)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:751
   9: trust_dns_proto::rr::domain::name::Name::from_encoded_str::h043d8a46c27231b5 (0x55ff96c689c9)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:542
  10: trust_dns_proto::rr::domain::name::Name::from_utf8::ha96d621bdc87c827 (0x55ff96c67247)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:477
  11: <trust_dns_proto::rr::domain::name::Name as core::str::FromStr>::from_str::h805af285cedfced4 (0x55ff96c6f1c3)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:1103
  12: trust_dns_resolver::system_conf::unix::into_resolver_config::h312cd3d9c7832911 (0x55ff96b570b9)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:81
  13: trust_dns_resolver::system_conf::unix::parse_resolv_conf::h27ba883798b92507 (0x55ff96b5650a)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:47
  14: trust_dns_resolver::system_conf::unix::read_resolv_conf::hfdbf0dcdb0b70596 (0x55ff96b56160)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:37
  15: trust_dns_resolver::system_conf::unix::read_system_conf::hd0b6a0ea50865d85 (0x55ff96b55d22)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:30
  16: trust_dns_resolver::async_resolver::AsyncResolver::from_system_conf::hfa0dba3b3ac01f39 (0x55ff96bdc08c)
             at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/async_resolver/mod.rs:196
Originally created by @Flakebi on GitHub (Dec 22, 2018). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/644 **Describe the bug** `AsyncResolver::from_system_conf` fails if the `resolv.conf` file contains a line like this: ``` search Speedport_000 ``` **To Reproduce** Steps to reproduce the behavior: 1. Add a line `search Speedport_000` to `/etc/resolv.conf` 1. Call `AsyncResolver::from_system_conf()` **Expected behavior** `trust-dns` works like a charm, as it does normally. **System:** - OS: Arch Linux - Architecture: x86_64 - Version: Latest (as of 2018-12-22) - rustc version: 1.33.0-nightly (96d1334e5 2018-12-14) **Version:** Crate: resolver Version: 0.10.1 **Additional context** My complete `resolv.conf`: ``` # Generated by NetworkManager search Speedport_000 nameserver 192.168.2.1 ``` Upper part of the backtrace: ``` Error parsing resolv.conf: ProtoError { inner: stack backtrace: 0: failure::backtrace::internal::InternalBacktrace::new::ha50a9f67574157be (0x55ff97537442) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/backtrace/internal.rs:44 1: failure::backtrace::Backtrace::new::h9119d83d8139bf81 (0x55ff975362bd) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/backtrace/mod.rs:111 2: <failure::context::Context<D>>::new::hf6b8acbfc40686fd (0x55ff96c14e89) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/failure-0.1.3/src/context.rs:84 3: <trust_dns_proto::error::ProtoError as core::convert::From<trust_dns_proto::error::ProtoErrorKind>>::from::ha1512e07bde176b8 (0x55ff96bfd670) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/error.rs:235 4: <T as core::convert::Into<U>>::into::hb745de55117c81d1 (0x55ff96bfd40a) at /rustc/96d1334e567237b1507cd277938e7ae2de75ff51/src/libcore/convert.rs:454 5: <trust_dns_proto::error::ProtoError as core::convert::From<alloc::string::String>>::from::h754d31b80be50be3 (0x55ff96bfd7a2) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/error.rs:254 6: <T as core::convert::Into<U>>::into::h54d7f9426f1d5d32 (0x55ff96c75410) at /rustc/96d1334e567237b1507cd277938e7ae2de75ff51/src/libcore/convert.rs:454 7: trust_dns_proto::rr::domain::label::Label::from_utf8::h490451d14e858eaa (0x55ff96c1f3ba) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/label.rs:64 8: <trust_dns_proto::rr::domain::name::LabelEncUtf8 as trust_dns_proto::rr::domain::name::LabelEnc>::to_label::hdc02f939975cf2a8 (0x55ff96c6d144) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:751 9: trust_dns_proto::rr::domain::name::Name::from_encoded_str::h043d8a46c27231b5 (0x55ff96c689c9) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:542 10: trust_dns_proto::rr::domain::name::Name::from_utf8::ha96d621bdc87c827 (0x55ff96c67247) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:477 11: <trust_dns_proto::rr::domain::name::Name as core::str::FromStr>::from_str::h805af285cedfced4 (0x55ff96c6f1c3) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-proto-0.6.1/src/rr/domain/name.rs:1103 12: trust_dns_resolver::system_conf::unix::into_resolver_config::h312cd3d9c7832911 (0x55ff96b570b9) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:81 13: trust_dns_resolver::system_conf::unix::parse_resolv_conf::h27ba883798b92507 (0x55ff96b5650a) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:47 14: trust_dns_resolver::system_conf::unix::read_resolv_conf::hfdbf0dcdb0b70596 (0x55ff96b56160) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:37 15: trust_dns_resolver::system_conf::unix::read_system_conf::hd0b6a0ea50865d85 (0x55ff96b55d22) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/system_conf/unix.rs:30 16: trust_dns_resolver::async_resolver::AsyncResolver::from_system_conf::hfa0dba3b3ac01f39 (0x55ff96bdc08c) at /home/sebi/.cargo/registry/src/github.com-1ecc6299db9ec823/trust-dns-resolver-0.10.1/src/async_resolver/mod.rs:196 ```
kerem 2026-03-07 23:05:39 +03:00
Author
Owner

@bluejekyll commented on GitHub (Dec 22, 2018):

Thanks for the report. I need to think about this one for a second. Technically speaking, _ is an invalid character in DNS names, which is what is triggering this failure to parse in the domain::Name implementation. _ is only allowed as a prepended character for use mainly in SRV record.

RFC 1034: https://tools.ietf.org/html/rfc1034#section-3.5
RFC 2782: https://tools.ietf.org/html/rfc2782 updates this to allow _ as a first char in the name.

Of course, it's clear that _ is being used in the wild, so we should probably allow it. Possibly a parse strict vs. parse relaxed mode, based on context. We already do this for names received over the wire, so perhaps we should do this for all untrusted sources of names, like resolv.conf.

<!-- gh-comment-id:449586742 --> @bluejekyll commented on GitHub (Dec 22, 2018): Thanks for the report. I need to think about this one for a second. Technically speaking, `_` is an invalid character in DNS names, which is what is triggering this failure to parse in the `domain::Name` implementation. `_` is only allowed as a prepended character for use mainly in SRV record. RFC 1034: https://tools.ietf.org/html/rfc1034#section-3.5 RFC 2782: https://tools.ietf.org/html/rfc2782 updates this to allow `_` as a first char in the name. Of course, it's clear that `_` is being used in the wild, so we should probably allow it. Possibly a parse strict vs. parse relaxed mode, based on context. We already do this for names received over the wire, so perhaps we should do this for all untrusted sources of names, like `resolv.conf`.
Author
Owner

@bluejekyll commented on GitHub (Dec 22, 2018):

RFC 2181: https://tools.ietf.org/html/rfc2181#section-11

The DNS itself places only one restriction on the particular labels
   that can be used to identify resource records.  That one restriction
   relates to the length of the label and the full name.  The length of
   any one label is limited to between 1 and 63 octets.

Clearly we’re being too restrictive with our names. I think the problem here is that, currently it’s the IDNA library we’re using for internationalization, and that is what is failing. To circumvent that, we can fail that, and then in “non-strict” mode, we can allow the name, though the fall back will be to treat it as ascii.

The earliest I can work on this is next week, but cannot make any promises.

<!-- gh-comment-id:449587998 --> @bluejekyll commented on GitHub (Dec 22, 2018): RFC 2181: https://tools.ietf.org/html/rfc2181#section-11 ``` The DNS itself places only one restriction on the particular labels that can be used to identify resource records. That one restriction relates to the length of the label and the full name. The length of any one label is limited to between 1 and 63 octets. ``` Clearly we’re being too restrictive with our names. I think the problem here is that, currently it’s the IDNA library we’re using for internationalization, and that is what is failing. To circumvent that, we can fail that, and then in “non-strict” mode, we can allow the name, though the fall back will be to treat it as ascii. The earliest I can work on this is next week, but cannot make any promises.
Author
Owner

@bluejekyll commented on GitHub (Dec 22, 2018):

Do you need this backported? to 0.10.x?

<!-- gh-comment-id:449603089 --> @bluejekyll commented on GitHub (Dec 22, 2018): Do you need this backported? to 0.10.x?
Author
Owner

@Flakebi commented on GitHub (Dec 23, 2018):

Thanks a lot for the fast answer and investigation!
I just stumbled over this today so I thought I’ll report it. For me there is no pressure on this, all projects where i use trust-dns are a lot less complete than this library ;).

So I don’t need it backported, thanks for asking. :)

<!-- gh-comment-id:449605023 --> @Flakebi commented on GitHub (Dec 23, 2018): Thanks a lot for the fast answer and investigation! I just stumbled over this today so I thought I’ll report it. For me there is no pressure on this, all projects where i use trust-dns are a lot less complete than this library ;). So I don’t need it backported, thanks for asking. :)
Author
Owner

@bluejekyll commented on GitHub (Jan 12, 2019):

This has been backported to the 0.10 resolver.

<!-- gh-comment-id:453783380 --> @bluejekyll commented on GitHub (Jan 12, 2019): This has been backported to the 0.10 resolver.
Author
Owner

@Victordmdb commented on GitHub (Jun 7, 2020):

Having a similar issue:

Error parsing resolve.conf: InvalidOption(5)

resolve.conf(remove IP addresses):

##Generated by chef
nameserver <IP1>
nameserver <IP2>
nameserver <IP3>
search nam.rootns.net lac.rootns.net eur.rootns.net apac.rootns.net rootns.net
options retrans:1 retry:1
<!-- gh-comment-id:640193949 --> @Victordmdb commented on GitHub (Jun 7, 2020): Having a similar issue: `Error parsing resolve.conf: InvalidOption(5)` resolve.conf(remove IP addresses): ``` ##Generated by chef nameserver <IP1> nameserver <IP2> nameserver <IP3> search nam.rootns.net lac.rootns.net eur.rootns.net apac.rootns.net rootns.net options retrans:1 retry:1 ```
Author
Owner

@bluejekyll commented on GitHub (Jun 7, 2020):

Do you want to open a new issue for this? The “retrans” option might be at issue. The actual parsing is done by a 3rd party library, so it would be good to see if the issue is there.

<!-- gh-comment-id:640247921 --> @bluejekyll commented on GitHub (Jun 7, 2020): Do you want to open a new issue for this? The “retrans” option might be at issue. The actual parsing is done by a 3rd party library, so it would be good to see if the issue is there.
Author
Owner

@Victordmdb commented on GitHub (Jun 7, 2020):

Sure, didnt know if it was worth opening an issue, since i wasn't too sure what the issue was

<!-- gh-comment-id:640248184 --> @Victordmdb commented on GitHub (Jun 7, 2020): Sure, didnt know if it was worth opening an issue, since i wasn't too sure what the issue was
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#260
No description provided.