From 21770f920fde4b1fa687834e1907552e89c669b7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 5 Mar 2026 16:04:20 -1000 Subject: [PATCH] Reject empty hostname in validate_hostname Empty name would cause memcpy underflow in the MAC suffix path. While unlikely in practice, validate explicitly to be safe. --- esphome/core/config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esphome/core/config.py b/esphome/core/config.py index a1b2c0d281e..5f3b4606eac 100644 --- a/esphome/core/config.py +++ b/esphome/core/config.py @@ -111,6 +111,8 @@ VALID_INCLUDE_EXTS = {".h", ".hpp", ".tcc", ".ino", ".cpp", ".c"} def validate_hostname(config): # Keep in sync with ESPHOME_DEVICE_NAME_MAX_LEN in esphome/core/entity_base.h + if not config[CONF_NAME]: + raise cv.Invalid("Hostname must not be empty", path=[CONF_NAME]) max_length = 31 if config[CONF_NAME_ADD_MAC_SUFFIX]: max_length -= 7 # "-AABBCC" is appended when add mac suffix option is used