]> git.proxmox.com Git - pve-installer.git/commitdiff
fix #5230: sys: net: properly escape FQDN regex
authorChristoph Heiss <c.heiss@proxmox.com>
Thu, 15 Feb 2024 12:39:38 +0000 (13:39 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 23 Feb 2024 16:28:54 +0000 (17:28 +0100)
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@proxmox.com>
 [ TL: fix bug # reference in code comments ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Proxmox/Sys/Net.pm
proxmox-installer-common/src/utils.rs
test/parse-fqdn.pl

index 2d2911614109ccdd536bda021c64096fc905bb9d..c2f3e9c049b609ede7c26fe4cb066279ec283de2 100644 (file)
@@ -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)";
index 0ed7438a0c64ab63a2c925d3bcdea9a000dc6be8..ddfd7a1e725317bba196ce22dd60160dd206752c 100644 (file)
@@ -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=5230
+        assert_eq!(
+            Fqdn::from("123@foo.com"),
+            Err(InvalidPart("123@foo".to_owned()))
+        );
     }
 
     #[test]
index 3009984821d71f30a5d9ddeb3ef1f8bf396e3e1e..6638fbe9ee3567bdc399e8a51ecee9a10d6a3a58 100755 (executable)
@@ -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=5230
+is_invalid('123@foo.com', ERR_ALPHANUM);
+
 done_testing();