From e039edde334541ecd4cfe50590f0e972180db114 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 26 Jul 2021 15:10:47 +0200 Subject: [PATCH] Enforce valid hostname --- tasmota/tasmota.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tasmota/tasmota.ino b/tasmota/tasmota.ino index aeab9e8ed..15a5cf519 100644 --- a/tasmota/tasmota.ino +++ b/tasmota/tasmota.ino @@ -382,7 +382,8 @@ void setup(void) { } char *s = TasmotaGlobal.hostname; while (*s) { - if (' ' == *s) { *s = '_'; } + if (!(isalnum(*s) || ('.' == *s))) { *s = '-'; } // Valid hostname chars are A..Z, a..z, 0..9, . and - + if ((s == TasmotaGlobal.hostname) && ('-' == *s)) { *s = 'x'; } // First char cannot be a dash so replace by an x s++; } snprintf_P(TasmotaGlobal.mqtt_topic, sizeof(TasmotaGlobal.mqtt_topic), ResolveToken(TasmotaGlobal.mqtt_topic).c_str());