diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index 1ac8779afe60fc..b3749b441d2ff1 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -688,6 +688,28 @@ impl Descriptor for WriteDescriptor { } } +/// Modify `fqdn!` to handle domain names ending with a dot +/// Handle parsing error +macro_rules! fqdn { + ($($args:expr),*) => {{ + #[allow(unused_mut)] + let mut str = std::string::String::new(); + $( str += "."; str += $args; )* + + + let fqdn_string = if str.ends_with('.') { + &str[1..str.len() - 1] + } else { + &str[1..] + }; + + match fqdn_string.parse::<$crate::FQDN>() { + Ok(fqdn) => fqdn, + Err(_) => $crate::FQDN::default(), + } + }} +} + #[derive(Clone, Eq, PartialEq, Hash, Debug)] pub struct NetDescriptor(pub FQDN, pub Option);