From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <c.heiss@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by lists.proxmox.com (Postfix) with ESMTPS id 4127891752
 for <pve-devel@lists.proxmox.com>; Thu, 15 Feb 2024 13:40:15 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 29B5E13030
 for <pve-devel@lists.proxmox.com>; Thu, 15 Feb 2024 13:40:15 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
 key-exchange X25519 server-signature RSA-PSS (2048 bits))
 (No client certificate requested)
 by firstgate.proxmox.com (Proxmox) with ESMTPS
 for <pve-devel@lists.proxmox.com>; Thu, 15 Feb 2024 13:40:13 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 611634844D
 for <pve-devel@lists.proxmox.com>; Thu, 15 Feb 2024 13:40:13 +0100 (CET)
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 15 Feb 2024 13:39:37 +0100
Message-ID: <20240215124004.1197676-5-c.heiss@proxmox.com>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20240215124004.1197676-1-c.heiss@proxmox.com>
References: <20240215124004.1197676-1-c.heiss@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.004 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
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 T_SCC_BODY_TEXT_LINE    -0.01 -
 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, parse-fqdn.pl]
Subject: [pve-devel] [PATCH installer 4/5] sys: net: do not allow overlong
 FQDNs as per RFCs and Debian spec
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 15 Feb 2024 12:40:15 -0000

Debian limits labels to 63 characters each and the total length to 253
characters [0].

[0] https://manpages.debian.org/stable/manpages/hostname.7.en.html

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 Proxmox/Sys/Net.pm | 5 ++++-
 test/parse-fqdn.pl | 4 ++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Proxmox/Sys/Net.pm b/Proxmox/Sys/Net.pm
index 3e01d37..2d29116 100644
--- a/Proxmox/Sys/Net.pm
+++ b/Proxmox/Sys/Net.pm
@@ -6,7 +6,7 @@ use warnings;
 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\-]*[a-zA-Z0-9])?)";
+our $HOSTNAME_RE = "(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{,61}?[a-zA-Z0-9])?)";
 our $FQDN_RE = "(?:${HOSTNAME_RE}\.)*${HOSTNAME_RE}";
 
 my $IPV4OCTET = "(?:25[0-5]|(?:2[0-4]|1[0-9]|[1-9])?[0-9])";
@@ -221,6 +221,9 @@ sub parse_fqdn : prototype($) {
     die "FQDN cannot be empty\n"
 	if !$text || length($text) == 0;
 
+    die "FQDN too long\n"
+	if length($text) > 253;
+
     die "Purely numeric hostnames are not allowed\n"
 	if $text =~ /^[0-9]+(?:\.|$)/;
 
diff --git a/test/parse-fqdn.pl b/test/parse-fqdn.pl
index 1ffb300..3009984 100755
--- a/test/parse-fqdn.pl
+++ b/test/parse-fqdn.pl
@@ -47,4 +47,8 @@ is_invalid('123.com', ERR_NUMERIC);
 is_parsed('foo123.com', ['foo123', 'com']);
 is_parsed('123foo.com', ['123foo', 'com']);
 
+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);
+
 done_testing();
-- 
2.43.0