Skip to content

Commit 2588315

Browse files
committed
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.
1 parent 1e415cf commit 2588315

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/app/app-platform/ContentAppPlatform.cpp

Lines changed: 5 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);
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);
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);
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);
359363
if (vendorApp.catalogVendorId == mContentAppFactory->GetPlatformCatalogVendorId())
360364
{
361365
return GetContentAppInternal(vendorApp);
@@ -671,6 +675,7 @@ 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);
674679

675680
Access::Privilege vendorPrivilege = mContentAppFactory->GetVendorPrivilege(targetVendorId);
676681

0 commit comments

Comments
 (0)