From 8491c0ab37953692561c87ba499f7dce02412cbf Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 26 Apr 2022 14:50:04 +0000 Subject: [PATCH] Do not send a hostname option when we don't have a hostname. 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 --- sbin/dhcpleased/frontend.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sbin/dhcpleased/frontend.c b/sbin/dhcpleased/frontend.c index 58c6153793f..2959a6c0d0f 100644 --- a/sbin/dhcpleased/frontend.c +++ b/sbin/dhcpleased/frontend.c @@ -1,4 +1,4 @@ -/* $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 @@ -971,7 +971,8 @@ build_packet(uint8_t message_type, char *if_name, uint32_t xid, #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); -- 2.20.1