Fix Zigbee crash #7187

This commit is contained in:
Hadinger 2019-12-12 22:22:34 +01:00
parent 04a952df99
commit 7d8a4f5077
1 changed files with 5 additions and 5 deletions

View File

@ -235,13 +235,14 @@ void ZigbeeInit(void)
* Commands * Commands
\*********************************************************************************************/ \*********************************************************************************************/
uint32_t strToUInt(const JsonVariant val) { uint32_t strToUInt(const JsonVariant &val) {
// if the string starts with 0x, it is considered Hex, otherwise it is an int // if the string starts with 0x, it is considered Hex, otherwise it is an int
if (val.is<unsigned int>()) { if (val.is<unsigned int>()) {
return val.as<unsigned int>(); return val.as<unsigned int>();
} else { } else {
if (val.is<char*>()) { if (val.is<const char*>()) {
return strtoull(val.as<char*>(), nullptr, 0); String sval = val.as<String>();
return strtoull(sval.c_str(), nullptr, 0);
} }
} }
return 0; // couldn't parse anything return 0; // couldn't parse anything
@ -593,6 +594,7 @@ void CmndZigbeeRead(void) {
const JsonVariant &val_attr = getCaseInsensitive(json, PSTR("Read")); const JsonVariant &val_attr = getCaseInsensitive(json, PSTR("Read"));
if (nullptr != &val_attr) { if (nullptr != &val_attr) {
uint16_t val = strToUInt(val_attr);
if (val_attr.is<JsonArray>()) { if (val_attr.is<JsonArray>()) {
JsonArray& attr_arr = val_attr; JsonArray& attr_arr = val_attr;
attrs_len = attr_arr.size() * 2; attrs_len = attr_arr.size() * 2;
@ -604,11 +606,9 @@ void CmndZigbeeRead(void) {
attrs[i++] = val & 0xFF; attrs[i++] = val & 0xFF;
attrs[i++] = val >> 8; attrs[i++] = val >> 8;
} }
} else { } else {
attrs_len = 2; attrs_len = 2;
attrs = new uint8_t[attrs_len]; attrs = new uint8_t[attrs_len];
uint16_t val = strToUInt(val_attr);
attrs[0] = val & 0xFF; // little endian attrs[0] = val & 0xFF; // little endian
attrs[1] = val >> 8; attrs[1] = val >> 8;
} }