Skip to content

Commit a7c7713

Browse files
authored
feat(zigbee_ep): check malloc return for null
1 parent cfe4457 commit a7c7713

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

libraries/Zigbee/src/ZigbeeEP.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) {
251251
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {
252252
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
253253
char *_read_manufacturer = (char *) malloc(zbstr->len + 1);
254+
if (_read_manufacturer == nullptr) {
255+
log_e("Failed to allocate memory for manufacturer data");
256+
xSemaphoreGive(lock);
257+
return;
258+
}
254259
memcpy(_read_manufacturer, zbstr->data, zbstr->len);
255260
_read_manufacturer[zbstr->len] = '\0';
256261
log_i("Peer Manufacturer is \"%s\"", _read_manufacturer);
@@ -259,6 +264,11 @@ void ZigbeeEP::zbReadBasicCluster(const esp_zb_zcl_attribute_t *attribute) {
259264
if (attribute->id == ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID && attribute->data.type == ESP_ZB_ZCL_ATTR_TYPE_CHAR_STRING && attribute->data.value) {
260265
zbstring_t *zbstr = (zbstring_t *)attribute->data.value;
261266
char *_read_model = (char *) malloc(zbstr->len + 1);
267+
if (_read_model == nullptr) {
268+
log_e("Failed to allocate memory for model data");
269+
xSemaphoreGive(lock);
270+
return;
271+
}
262272
memcpy(_read_model, zbstr->data, zbstr->len);
263273
_read_model[zbstr->len] = '\0';
264274
log_i("Peer Model is \"%s\"", _read_model);

0 commit comments

Comments
 (0)