From 93731b576c5b4162e9fc22b8de9130634920d284 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Tue, 20 May 2025 14:18:32 -0400 Subject: [PATCH] RUST-2219 Relax domain name parsing --- src/error.rs | 8 ++++++++ src/runtime/resolver.rs | 12 +++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/error.rs b/src/error.rs index 796b7231f..1ca984f4f 100644 --- a/src/error.rs +++ b/src/error.rs @@ -290,6 +290,14 @@ impl Error { .into() } + #[cfg(feature = "dns-resolver")] + pub(crate) fn from_resolve_proto_error(error: hickory_proto::error::ProtoError) -> Self { + ErrorKind::DnsResolve { + message: error.to_string(), + } + .into() + } + pub(crate) fn is_non_timeout_network_error(&self) -> bool { matches!(self.kind.as_ref(), ErrorKind::Io(ref io_err) if io_err.kind() != std::io::ErrorKind::TimedOut) } diff --git a/src/runtime/resolver.rs b/src/runtime/resolver.rs index c67acb113..bd75a9d09 100644 --- a/src/runtime/resolver.rs +++ b/src/runtime/resolver.rs @@ -2,7 +2,7 @@ use hickory_resolver::{ config::ResolverConfig, error::ResolveErrorKind, lookup::{SrvLookup, TxtLookup}, - IntoName, + Name, }; use crate::error::{Error, Result}; @@ -25,17 +25,19 @@ impl AsyncResolver { } impl AsyncResolver { - pub async fn srv_lookup(&self, query: N) -> Result { + pub async fn srv_lookup(&self, query: &str) -> Result { + let name = Name::from_str_relaxed(query).map_err(Error::from_resolve_proto_error)?; let lookup = self .resolver - .srv_lookup(query) + .srv_lookup(name) .await .map_err(Error::from_resolve_error)?; Ok(lookup) } - pub async fn txt_lookup(&self, query: N) -> Result> { - let lookup_result = self.resolver.txt_lookup(query).await; + pub async fn txt_lookup(&self, query: &str) -> Result> { + let name = Name::from_str_relaxed(query).map_err(Error::from_resolve_proto_error)?; + let lookup_result = self.resolver.txt_lookup(name).await; match lookup_result { Ok(lookup) => Ok(Some(lookup)), Err(e) => match e.kind() {