Skip to content

[NXP] Missing null checks #71954

@Alami-Amine

Description

@Alami-Amine

Add NULL checks for malloc in NXP BLE and S200 crypto

Site 1: src/platform/nxp/common/ble/BLEManagerCommon.cpp:1382

adv_data = (gapAdStructure_t *) malloc(...);
adv_data[0].length = ...;   // ← NULL deref on OOM

Site 2: [src/platform/nxp/common/crypto/S200/CHIPCryptoPalS200.cpp:364-368

node = (sha256_node *) malloc(sizeof(...));    // ← unchecked
node->data = (uint8_t *) malloc(...);          // ← unchecked, also leaks node on OOM
memcpy(node->data, ...);                        // ← second NULL deref

Fix template (both sites): standard NULL-check pattern:

adv_data = (gapAdStructure_t *) malloc(size);
VerifyOrReturnError(adv_data != nullptr, CHIP_ERROR_NO_MEMORY);
// ... use adv_data

For site 2, also fix the leak on the second malloc failure:

node->data = (uint8_t *) malloc(...);
if (node->data == nullptr) {
    free(node);
    return CHIP_ERROR_NO_MEMORY;
}

Metadata

Metadata

Assignees

Labels

nxpNXP platform

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions