Skip to content

Commit eeb36ee

Browse files
Add nullptr checks in ContentAppPlatform mContentAppFactory (project-chip#41827)
* Add nullptr checks in ContentAppPlatform mContentAppFactory Add additional checks inside ContentAppPlatform to first check if mContentAppFactory is null to prevent nullptr dereference crashes. [Problem] There are several dereferences to mContentAppFactory without first checking if pointer is valid. * Update src/app/app-platform/ContentAppPlatform.cpp Error log when mContentAppFactory is null. Co-authored-by: chrisdecenzo <[email protected]> * Update src/app/app-platform/ContentAppPlatform.cpp Error log when mContentAppFactory is null. Co-authored-by: chrisdecenzo <[email protected]> * Update src/app/app-platform/ContentAppPlatform.cpp Error log when mContentAppFactory is null. Co-authored-by: chrisdecenzo <[email protected]> * Apply suggestions from code review Co-authored-by: chrisdecenzo <[email protected]> * Restyled changes --------- Co-authored-by: chrisdecenzo <[email protected]>
1 parent 5098c63 commit eeb36ee

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/app/app-platform/ContentAppPlatform.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ void ContentAppPlatform::SetupAppPlatform()
291291

292292
ContentApp * ContentAppPlatform::GetContentAppInternal(const CatalogVendorApp & vendorApp)
293293
{
294+
VerifyOrReturnValue(mContentAppFactory != nullptr, nullptr, ChipLogError(DeviceLayer, "mContentAppFactory is null"));
294295
if (vendorApp.catalogVendorId != mContentAppFactory->GetPlatformCatalogVendorId())
295296
{
296297
return nullptr;
@@ -325,6 +326,7 @@ ContentApp * ContentAppPlatform::LoadContentAppInternal(const CatalogVendorApp &
325326
ContentApp * ContentAppPlatform::LoadContentAppByClient(uint16_t vendorId, uint16_t productId)
326327
{
327328
ChipLogProgress(DeviceLayer, "LoadContentAppByVendorId() - vendorId %d, productId %d", vendorId, productId);
329+
VerifyOrReturnValue(mContentAppFactory != nullptr, nullptr, ChipLogError(DeviceLayer, "mContentAppFactory is null"));
328330

329331
CatalogVendorApp vendorApp;
330332
CHIP_ERROR err = mContentAppFactory->LookupCatalogVendorApp(vendorId, productId, &vendorApp);
@@ -339,6 +341,7 @@ ContentApp * ContentAppPlatform::LoadContentAppByClient(uint16_t vendorId, uint1
339341

340342
ContentApp * ContentAppPlatform::LoadContentApp(const CatalogVendorApp & vendorApp)
341343
{
344+
VerifyOrReturnValue(mContentAppFactory != nullptr, nullptr, ChipLogError(DeviceLayer, "mContentAppFactory is null"));
342345
if (vendorApp.catalogVendorId == mContentAppFactory->GetPlatformCatalogVendorId())
343346
{
344347
return LoadContentAppInternal(vendorApp);
@@ -356,6 +359,7 @@ ContentApp * ContentAppPlatform::LoadContentApp(const CatalogVendorApp & vendorA
356359

357360
ContentApp * ContentAppPlatform::GetContentApp(const CatalogVendorApp & vendorApp)
358361
{
362+
VerifyOrReturnValue(mContentAppFactory != nullptr, nullptr, ChipLogError(DeviceLayer, "mContentAppFactory is null"));
359363
if (vendorApp.catalogVendorId == mContentAppFactory->GetPlatformCatalogVendorId())
360364
{
361365
return GetContentAppInternal(vendorApp);
@@ -671,6 +675,8 @@ CHIP_ERROR ContentAppPlatform::ManageClientAccess(Messaging::ExchangeManager & e
671675
{
672676
VerifyOrReturnError(successCb != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
673677
VerifyOrReturnError(failureCb != nullptr, CHIP_ERROR_INVALID_ARGUMENT);
678+
VerifyOrReturnError(mContentAppFactory != nullptr, CHIP_ERROR_INCORRECT_STATE,
679+
ChipLogError(DeviceLayer, "mContentAppFactory is null"));
674680

675681
Access::Privilege vendorPrivilege = mContentAppFactory->GetVendorPrivilege(targetVendorId);
676682

0 commit comments

Comments
 (0)