From 4c0a85ba0f18f59d4482f398d772e8a0907cde84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sch=C3=BCler-Maroldt?= Date: Sat, 25 Apr 2020 00:55:39 +0200 Subject: [PATCH] CommandHandler() optimize and maybe security fix --- tasmota/support_command.ino | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index a60a57b4c..6a8608560 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -204,14 +204,19 @@ void CommandHandler(char* topicBuf, char* dataBuf, uint32_t data_len) if (type != nullptr) { type++; uint32_t i; - for (i = 0; i < strlen(type); i++) { - type[i] = toupper(type[i]); + int nLen; // strlen(type) + char *s = type; + for (nLen = 0; *s; s++, nLen++) { + *s=toupper(*s); } - while (isdigit(type[i-1])) { - i--; + i = nLen; + if (i > 0) { // may be 0 + while (isdigit(type[i-1])) { + i--; + } } - if (i < strlen(type)) { - index = atoi(type +i); + if (i < nLen) { + index = atoi(type + i); user_index = true; } type[i] = '\0';