The minimum length of a hostname is 1 according to RFC 2132.
Found the hard way by Ibrahim Khalifa (ibo AT trukonsult.se) with DHCP
Relay on a Cisco ASA in the installer where we don't have a hostname
yet.
Ibrahim also provided a diff which I simplified a bit.
OK tb
-/* $OpenBSD: frontend.c,v 1.28 2022/01/04 06:20:37 florian Exp $ */
+/* $OpenBSD: frontend.c,v 1.29 2022/04/26 14:50:04 florian Exp $ */
/*
* Copyright (c) 2017, 2021 Florian Obser <florian@openbsd.org>
#endif /* SMALL */
{
if (gethostname(dhcp_hostname + 2,
- sizeof(dhcp_hostname) - 2) == 0) {
+ sizeof(dhcp_hostname) - 2) == 0 &&
+ dhcp_hostname[2] != '\0') {
if ((c = strchr(dhcp_hostname + 2, '.')) != NULL)
*c = '\0';
dhcp_hostname[1] = strlen(dhcp_hostname + 2);