From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 153411FF385 for ; Wed, 24 Apr 2024 18:15:50 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B78A511C4F; Wed, 24 Apr 2024 18:15:54 +0200 (CEST) From: Stefan Hanreich To: pve-devel@lists.proxmox.com Date: Wed, 24 Apr 2024 18:15:20 +0200 Message-Id: <20240424161520.466900-1-s.hanreich@proxmox.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.270 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [alias.rs, parse.rs, proxmox.com] Subject: [pve-devel] [PATCH proxmox-firewall] fix #5410: config: fix naming scheme for names in firewall config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" This should bring the allowed names on par with the pve-firewall naming scheme [1]. [1] https://git.proxmox.com/?p=pve-firewall.git;a=blob;f=src/PVE/Firewall.pm;h=0abfeccffc94cec940760e69a894e392dc33f151;hb=29b48c381d14bf425232dc65c9c0d18f95c8f222#l51 Signed-off-by: Stefan Hanreich --- proxmox-ve-config/src/firewall/parse.rs | 8 +++++++- proxmox-ve-config/src/firewall/types/alias.rs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/proxmox-ve-config/src/firewall/parse.rs b/proxmox-ve-config/src/firewall/parse.rs index 93cf014..7bf00c0 100644 --- a/proxmox-ve-config/src/firewall/parse.rs +++ b/proxmox-ve-config/src/firewall/parse.rs @@ -2,6 +2,8 @@ use std::fmt; use anyhow::{bail, format_err, Error}; +const NAME_SPECIAL_CHARACTERS: [u8; 2] = [b'-', b'_']; + /// Parses out a "name" which can be alphanumeric and include dashes. /// /// Returns `None` if the name part would be empty. @@ -16,10 +18,14 @@ use anyhow::{bail, format_err, Error}; /// assert_eq!(match_name(" someremainder"), None); /// ``` pub fn match_name(line: &str) -> Option<(&str, &str)> { + if !line.starts_with(|c: char| c.is_ascii_alphabetic()) { + return None; + } + let end = line .as_bytes() .iter() - .position(|&b| !(b.is_ascii_alphanumeric() || b == b'-')); + .position(|&b| !(b.is_ascii_alphanumeric() || NAME_SPECIAL_CHARACTERS.contains(&b))); let (name, rest) = match end { Some(end) => line.split_at(end), diff --git a/proxmox-ve-config/src/firewall/types/alias.rs b/proxmox-ve-config/src/firewall/types/alias.rs index 43c6486..e6aa30d 100644 --- a/proxmox-ve-config/src/firewall/types/alias.rs +++ b/proxmox-ve-config/src/firewall/types/alias.rs @@ -147,6 +147,20 @@ impl FromStr for Alias { mod tests { use super::*; + #[test] + fn test_parse_alias() { + for alias in [ + "local_network 10.0.0.0/32", + "test-_123-___-a---- 10.0.0.1/32", + ] { + alias.parse::().expect("valid alias"); + } + + for alias in ["-- 10.0.0.1/32", "0asd 10.0.0.1/32", "__test 10.0.0.0/32"] { + alias.parse::().expect_err("invalid alias"); + } + } + #[test] fn test_parse_alias_name() { for name in ["dc/proxmox_123", "guest/proxmox-123"] { -- 2.39.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel