From 3aabf9f83ec385ca735479fcbfa7c8c142e1509a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jake=20Buchholz=20G=C3=B6kt=C3=BCrk?= Date: Thu, 29 May 2025 19:31:34 -0700 Subject: [PATCH] validate hostname value lengths --- CHANGELOG.md | 3 +++ lib/tiny-cloud/init | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9393de4..ed2a6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ * Alpine autoinstall - allow override disk and reboot and set swap (@ncopa) +* Warn when hostname is too long (per RFC-1035) instead of setting invalid + value. + ## 2024-12-03 - Tiny Cloud v3.1.0 diff --git a/lib/tiny-cloud/init b/lib/tiny-cloud/init index 8eb7329..f633777 100644 --- a/lib/tiny-cloud/init +++ b/lib/tiny-cloud/init @@ -226,13 +226,19 @@ init__set_hostname() { log -i -t "$phase" info "$ACTION: no hostname set" return fi - - local host="${fqdn%%\.*}" - if [ -z "$host" ]; then - log -i -t "$phase" warning "$ACTION: invalid hostname '$fqdn'" + if [ ${#fqdn} -gt 255 ]; then + log -i -t "$phase" warning "$ACTION: hostname exceeds 255 chars '$fqdn'" + return 1 + fi + local host="${fqdn%%\.*}" + if [ -z "$host" ]; then + log -i -t "$phase" warning "$ACTION: unable to extract short hostname from '$fqdn'" + return 1 + fi + if [ ${#host} -gt 63 ]; then + log -i -t "$phase" warning "$ACTION: short hostname exceeds 63 chars '$host'" return 1 fi - mkdir -p "$ETC" echo "$host" > "$ETC"/hostname $MOCK hostname -F "$ETC"/hostname