From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id B2C7C1FF179 for ; Wed, 26 Nov 2025 19:08:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 89F5A13671; Wed, 26 Nov 2025 19:09:04 +0100 (CET) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Wed, 26 Nov 2025 19:07:16 +0100 Message-ID: <20251126180819.817240-3-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251126180819.817240-1-s.ivanov@proxmox.com> References: <20251126180819.817240-1-s.ivanov@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1764180504201 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.070 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_SHORT 0.001 Use of a URL Shortener for very short URL RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches 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. [options.rs, docs.rs] Subject: [pve-devel] [PATCH installer 2/2] common: pinning: use pve-iface regular expression for validation 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" the previous attempts at mimicking the `pve-iface` validation in pve-common mis-read the validation, or missed some corner-cases. So instead of trying to rebuild a regex validation, simply copy the regular expression from pve-common. Following the recommendation at https://docs.rs/regex/latest/regex/#overview by using RegexBuilder for case-insensitive matching. I kept the length-check at {1,20}, to have this as close to the original as possible, as we restrict the length to 15 in the checks before anyways. Fixes: 47700a5 ("common: pinning: require first character to be lower-case ascii") Reported-by: Thomas Lamprecht Signed-off-by: Stoiko Ivanov --- proxmox-installer-common/src/options.rs | 51 +++++++++---------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/proxmox-installer-common/src/options.rs b/proxmox-installer-common/src/options.rs index 34d0725..fbc0207 100644 --- a/proxmox-installer-common/src/options.rs +++ b/proxmox-installer-common/src/options.rs @@ -1,5 +1,5 @@ use anyhow::{Result, bail}; -use regex::Regex; +use regex::{Regex, RegexBuilder}; use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::{IpAddr, Ipv4Addr}; @@ -517,25 +517,18 @@ impl NetworkInterfacePinningOptions { ); } - if name.chars().all(char::is_numeric) { - bail!( - "interface name '{name}' for '{mac}' is invalid: name must not be fully numeric" - ); - } - // Mimicking the `pve-iface` schema verification - if !name.starts_with(|c: char| c.is_ascii_lowercase()) { - bail!( - "interface name '{name}' for '{mac}' is invalid: name must start with a lowercase letter" - ); - } - - if !name - .chars() - .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') - { + static RE: OnceLock = OnceLock::new(); + let re = RE.get_or_init(|| { + RegexBuilder::new(r"^[a-z][a-z0-9_]{1,20}([:\.]\d+)?$") + .case_insensitive(true) + .build() + .unwrap() + }); + + if !re.is_match(name) { bail!( - "interface name '{name}' for '{mac}' is invalid: name must only consist of alphanumeric lowercase characters and underscores" + "interface name '{name}' for '{mac}' is invalid: name must start with a letter and contain only ascii characters, digits and underscores" ); } @@ -1022,7 +1015,7 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name 'nic-' for 'ab:cd:ef:12:34:56' is invalid: name must only consist of alphanumeric lowercase characters and underscores" + "interface name 'nic-' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter and contain only ascii characters, digits and underscores" ) } @@ -1037,7 +1030,7 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name '0nic' for 'ab:cd:ef:12:34:56' is invalid: name must start with a lowercase letter" + "interface name '0nic' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter and contain only ascii characters, digits and underscores" ); options @@ -1048,34 +1041,26 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name '_a' for 'ab:cd:ef:12:34:56' is invalid: name must start with a lowercase letter" + "interface name '_a' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter and contain only ascii characters, digits and underscores" ); } #[test] - fn network_interface_pinning_options_fail_on_uppercase_char() { + fn network_interface_pinning_options_pass_on_uppercase_char() { let mut options = NetworkInterfacePinningOptions::default(); options .mapping .insert("ab:cd:ef:12:34:56".to_owned(), "Nic0".to_owned()); let res = options.verify(); - assert!(res.is_err()); - assert_eq!( - res.unwrap_err().to_string(), - "interface name 'Nic0' for 'ab:cd:ef:12:34:56' is invalid: name must start with a lowercase letter" - ); + assert!(res.is_ok()); options .mapping .insert("ab:cd:ef:12:34:56".to_owned(), "nIc0".to_owned()); let res = options.verify(); - assert!(res.is_err()); - assert_eq!( - res.unwrap_err().to_string(), - "interface name 'nIc0' for 'ab:cd:ef:12:34:56' is invalid: name must only consist of alphanumeric lowercase characters and underscores" - ); + assert!(res.is_ok()); options .mapping @@ -1096,7 +1081,7 @@ mod tests { assert!(res.is_err()); assert_eq!( res.unwrap_err().to_string(), - "interface name '12345' for 'ab:cd:ef:12:34:56' is invalid: name must not be fully numeric" + "interface name '12345' for 'ab:cd:ef:12:34:56' is invalid: name must start with a letter and contain only ascii characters, digits and underscores" ) } } -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel