From: Christoph Heiss Date: Thu, 15 Feb 2024 12:39:37 +0000 (+0100) Subject: sys: net: do not allow overlong FQDNs as per RFCs and Debian spec X-Git-Url: https://git.proxmox.com/?p=pve-installer.git;a=commitdiff_plain;h=1a5665378b75d5b7d3b838c39c93600bea7cb609 sys: net: do not allow overlong FQDNs as per RFCs and Debian spec 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 --- 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();