From a1d76a35653a70a40659c1674d3b44242af6ef81 Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 27 Jan 2026 09:56:59 +1100 Subject: [PATCH 1/2] Fix stack overflow. --- radio/src/MultiProtoDefs.h | 1 + radio/src/io/multi_protolist.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/radio/src/MultiProtoDefs.h b/radio/src/MultiProtoDefs.h index 462430befc5..68d18bd6080 100644 --- a/radio/src/MultiProtoDefs.h +++ b/radio/src/MultiProtoDefs.h @@ -163,6 +163,7 @@ enum ModuleSubtypeMulti { // // Common list of Multi protocol names. Needs to match enum ModuleSubtypeMulti // +#define MAX_MPM_NAME_LEN 8 // Update if a protocol with a longer name is added !!! #define KNOWN_PROTO_NAMES \ "FlySky","Hubsan","FrSky D","Hisky","V2x2","DSM","Devo","YD717","KN","SymaX",\ "SLT","CX10","CG023","Bayang","FrSky X","ESky","MT99XX","MJXq","Shenqi","FY326",\ diff --git a/radio/src/io/multi_protolist.cpp b/radio/src/io/multi_protolist.cpp index e1021b8bedc..bd58fc99281 100644 --- a/radio/src/io/multi_protolist.cpp +++ b/radio/src/io/multi_protolist.cpp @@ -322,7 +322,7 @@ void MultiRfProtocols::fillBuiltinProtos() if (pdef->protocol == MM_RF_CUSTOM_SELECTED) break; // skip custom proto - char tmp[8]; + char tmp[MAX_MPM_NAME_LEN + 2]; rfProto.label = getStringAtIndex(tmp, STR_MULTI_PROTOCOLS, pdef->protocol); rfProto.flags = (pdef->failsafe ? 0x01 : 0) | (pdef->disable_ch_mapping ? 0x02 : 0); From 977eefdefe92880a17d05506f4356997edd0752c Mon Sep 17 00:00:00 2001 From: philmoz Date: Tue, 27 Jan 2026 10:57:27 +1100 Subject: [PATCH 2/2] Remove need for tmp buffer. --- radio/src/MultiProtoDefs.h | 1 - radio/src/io/multi_protolist.cpp | 7 ++----- radio/src/strhelpers.cpp | 5 +++++ radio/src/strhelpers.h | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/radio/src/MultiProtoDefs.h b/radio/src/MultiProtoDefs.h index 68d18bd6080..462430befc5 100644 --- a/radio/src/MultiProtoDefs.h +++ b/radio/src/MultiProtoDefs.h @@ -163,7 +163,6 @@ enum ModuleSubtypeMulti { // // Common list of Multi protocol names. Needs to match enum ModuleSubtypeMulti // -#define MAX_MPM_NAME_LEN 8 // Update if a protocol with a longer name is added !!! #define KNOWN_PROTO_NAMES \ "FlySky","Hubsan","FrSky D","Hisky","V2x2","DSM","Devo","YD717","KN","SymaX",\ "SLT","CX10","CG023","Bayang","FrSky X","ESky","MT99XX","MJXq","Shenqi","FY326",\ diff --git a/radio/src/io/multi_protolist.cpp b/radio/src/io/multi_protolist.cpp index bd58fc99281..cef11a0ba28 100644 --- a/radio/src/io/multi_protolist.cpp +++ b/radio/src/io/multi_protolist.cpp @@ -162,9 +162,7 @@ std::string MultiRfProtocols::getProtoLabel(unsigned int proto) const if (status.protocolName[0] && status.isValid()) { return std::string(status.protocolName); } else if (proto <= MODULE_SUBTYPE_MULTI_LAST) { - char tmp[8]; - getStringAtIndex(tmp, STR_MULTI_PROTOCOLS, proto); - return std::string(tmp); + return getStringAtIndex(STR_MULTI_PROTOCOLS, proto); } } else { int idx = getIndex(proto); @@ -322,8 +320,7 @@ void MultiRfProtocols::fillBuiltinProtos() if (pdef->protocol == MM_RF_CUSTOM_SELECTED) break; // skip custom proto - char tmp[MAX_MPM_NAME_LEN + 2]; - rfProto.label = getStringAtIndex(tmp, STR_MULTI_PROTOCOLS, pdef->protocol); + rfProto.label = getStringAtIndex(STR_MULTI_PROTOCOLS, pdef->protocol); rfProto.flags = (pdef->failsafe ? 0x01 : 0) | (pdef->disable_ch_mapping ? 0x02 : 0); diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index cb07c912fa8..ec16dcb34f5 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -120,6 +120,11 @@ char *strcat_zchar(char *dest, const char *name, uint8_t size, #endif #if !defined(BOOT) +std::string getStringAtIndex(const char *const *s, int idx) +{ + return std::string(s[idx]); +} + char *getStringAtIndex(char *dest, const char *const *s, int idx) { strcpy(dest, s[idx]); diff --git a/radio/src/strhelpers.h b/radio/src/strhelpers.h index 0f8928b4ece..67632ad68fb 100644 --- a/radio/src/strhelpers.h +++ b/radio/src/strhelpers.h @@ -106,6 +106,7 @@ void formatNumberAsString(char *buffer, const uint8_t buffer_size, int32_t val, #if !defined(BOOT) char *getStringAtIndex(char *dest, const char *const *s, int idx); +std::string getStringAtIndex(const char *const *s, int idx); char *strAppendStringWithIndex(char *dest, const char *s, int idx); #define LEN_TIMER_STRING 10 // "-00:00:00" char *getTimerString(char *dest, int32_t tme,