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 BE4FD1FF179 for ; Wed, 26 Nov 2025 19:08:56 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 05A381370A; Wed, 26 Nov 2025 19:09:05 +0100 (CET) From: Stoiko Ivanov To: pve-devel@lists.proxmox.com Date: Wed, 26 Nov 2025 19:07:15 +0100 Message-ID: <20251126180819.817240-2-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: 1764180504105 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 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. [net.pm, validate-link-pin-map.pl] Subject: [pve-devel] [PATCH installer 1/2] sys: net: use literal 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" Instead of trying to do partial checks to validate the interface name in accordance with `pve-iface` in pve-common, just copy the regular expression. This comes at the expense of a longer and unified error-message for different errors, but I'd consider this acceptable. The length of {1,20} is also copied from the pve-iface validation regex to make this a literal copy. The kernel restricts it to 15 bytes (16 with terminating \0) - but we check for the actual length boundaries before anyways. Fixes: fc9e720 ("sys: net: fix error-message for interface names first character") Reported-by: Thomas Lamprecht Signed-off-by: Stoiko Ivanov --- Proxmox/Sys/Net.pm | 15 +++------------ test/validate-link-pin-map.pl | 12 ++++++++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm index 37feee1..e3b3b56 100644 --- a/Proxmox/Sys/Net.pm +++ b/Proxmox/Sys/Net.pm @@ -335,18 +335,9 @@ sub validate_link_pin_map : prototype($) { . " characters\n"; } - if ($name =~ m/^[0-9]+$/) { - die "interface name '$name' for '$mac' is invalid: " - . "name must not be fully numeric\n"; - } - - if ($name !~ m/^[a-z]/) { - die "interface name '$name' for '$mac' is invalid: name must start with a lower-case letter\n"; - } - - if ($name !~ m/^[a-zA-Z_][a-zA-Z0-9_]*$/) { - die "interface name '$name' for '$mac' is invalid: " - . "name must only consist of alphanumeric characters and underscores\n"; + if ($name !~ m/^[a-z][a-z0-9_]{1,20}([:\.]\d+)?$/i) { + die "interface name '$name' for '$mac' is invalid: name must start with a letter and " + . "contain only ascii characters, digits and underscores\n"; } if ($reverse_mapping->{$name}) { diff --git a/test/validate-link-pin-map.pl b/test/validate-link-pin-map.pl index 3fbd0e4..2cb8a90 100755 --- a/test/validate-link-pin-map.pl +++ b/test/validate-link-pin-map.pl @@ -38,28 +38,32 @@ like($@, qr/12:34:56:ab:cd:ef/, "duplicate error message contains expected mac a eval { validate_link_pin_map({ 'ab:cd:ef:12:34:56' => 'nic-' }) }; is( $@, - "interface name 'nic-' for 'ab:cd:ef:12:34:56' is invalid: name must only consist of alphanumeric characters and underscores\n", + "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\n", "name with dash is rejected", ); eval { validate_link_pin_map({ 'ab:cd:ef:12:34:56' => '0nic' }) }; is( $@, - "interface name '0nic' for 'ab:cd:ef:12:34:56' is invalid: name must start with a lower-case letter\n", + "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\n", "name starting with number is rejected", ); eval { validate_link_pin_map({ 'ab:cd:ef:12:34:56' => '_a' }) }; is( $@, - "interface name '_a' for 'ab:cd:ef:12:34:56' is invalid: name must start with a lower-case letter\n", + "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\n", "name starting with underscore is rejected", ); eval { validate_link_pin_map({ 'ab:cd:ef:12:34:56' => '12345' }) }; is( $@, - "interface name '12345' for 'ab:cd:ef:12:34:56' is invalid: name must not be fully numeric\n", + "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\n", "fully numeric name is rejected", ); -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel