[pve-devel] [PATCH installer 5/5] fix #5230: sys: net: properly escape FQDN regex
Christoph Heiss
c.heiss at proxmox.com
Thu Feb 15 13:39:38 CET 2024
Due to interpolation, the \. sequence must be double-escaped.
Previously, this would result in a non-escaped dot, thus matching much
more liberally than it should.
Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
Proxmox/Sys/Net.pm | 2 +-
proxmox-installer-common/src/utils.rs | 6 ++++++
test/parse-fqdn.pl | 3 +++
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm
index 2d29116..c2f3e9c 100644
--- a/Proxmox/Sys/Net.pm
+++ b/Proxmox/Sys/Net.pm
@@ -7,7 +7,7 @@ use base qw(Exporter);
our @EXPORT_OK = qw(parse_ip_address parse_ip_mask parse_fqdn);
our $HOSTNAME_RE = "(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{,61}?[a-zA-Z0-9])?)";
-our $FQDN_RE = "(?:${HOSTNAME_RE}\.)*${HOSTNAME_RE}";
+our $FQDN_RE = "(?:${HOSTNAME_RE}\\.)*${HOSTNAME_RE}";
my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
my $IPV4RE = "(?:(?:$IPV4OCTET\\.){3}$IPV4OCTET)";
diff --git a/proxmox-installer-common/src/utils.rs b/proxmox-installer-common/src/utils.rs
index 0ed7438..03efdd7 100644
--- a/proxmox-installer-common/src/utils.rs
+++ b/proxmox-installer-common/src/utils.rs
@@ -309,6 +309,12 @@ mod tests {
Fqdn::from(&format!("{}.com", "a".repeat(64))),
Err(InvalidPart("a".repeat(64))),
);
+
+ // https://bugzilla.proxmox.com/show_bug.cgi?id=3497
+ assert_eq!(
+ Fqdn::from("123 at foo.com"),
+ Err(InvalidPart("123 at foo".to_owned()))
+ );
}
#[test]
diff --git a/test/parse-fqdn.pl b/test/parse-fqdn.pl
index 3009984..df8739d 100755
--- a/test/parse-fqdn.pl
+++ b/test/parse-fqdn.pl
@@ -51,4 +51,7 @@ is_parsed('a' x 63 . '.com', ['a' x 63, 'com']);
is_invalid('a' x 250 . '.com', ERR_TOOLONG);
is_invalid('a' x 64 . '.com', ERR_ALPHANUM);
+# https://bugzilla.proxmox.com/show_bug.cgi?id=3497
+is_invalid('123 at foo.com', ERR_ALPHANUM);
+
done_testing();
--
2.43.0
More information about the pve-devel
mailing list