public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 5/5] fix #5230: sys: net: properly escape FQDN regex
Date: Thu, 15 Feb 2024 13:39:38 +0100	[thread overview]
Message-ID: <20240215124004.1197676-6-c.heiss@proxmox.com> (raw)
In-Reply-To: <20240215124004.1197676-1-c.heiss@proxmox.com>

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>
---
 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@foo.com"),
+            Err(InvalidPart("123@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@foo.com', ERR_ALPHANUM);
+
 done_testing();
-- 
2.43.0





  parent reply	other threads:[~2024-02-15 12:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-15 12:39 [pve-devel] [PATCH installer 0/5] proxinstall, tui: improve hostname/FQDN validation Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 1/5] common: fqdn: do not allow overlong FQDNs as per Debian spec Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 2/5] common: fqdn: implement case-insensitive comparison as per RFC 952 Christoph Heiss
2024-02-23 16:10   ` Thomas Lamprecht
2024-02-15 12:39 ` [pve-devel] [PATCH installer 3/5] proxinstall: avoid open-coding FQDN sanity check Christoph Heiss
2024-02-15 12:39 ` [pve-devel] [PATCH installer 4/5] sys: net: do not allow overlong FQDNs as per RFCs and Debian spec Christoph Heiss
2024-02-15 12:39 ` Christoph Heiss [this message]
2024-02-23 16:27   ` [pve-devel] [PATCH installer 5/5] fix #5230: sys: net: properly escape FQDN regex Thomas Lamprecht
2024-02-26  9:04     ` Christoph Heiss
2024-02-23 16:31 ` [pve-devel] applied-series: [PATCH installer 0/5] proxinstall, tui: improve hostname/FQDN validation Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240215124004.1197676-6-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal