Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResolverProxy::Init does not check for allocation failure #12943

Closed
msandstedt opened this issue Dec 13, 2021 · 0 comments · Fixed by #13290
Closed

ResolverProxy::Init does not check for allocation failure #12943

msandstedt opened this issue Dec 13, 2021 · 0 comments · Fixed by #13290

Comments

@msandstedt
Copy link
Contributor

Problem

chip::Platform::New can return nullptr on allocation failure. But ResolverProxy::Init is not checking for this:

class ResolverProxy : public Resolver
{
public:
    ResolverProxy() {}

    // Resolver interface.
    CHIP_ERROR Init(Inet::InetLayer * inetLayer = nullptr) override
    {   
        ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(inetLayer));
        VerifyOrReturnError(mDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE);
        mDelegate = chip::Platform::New<ResolverDelegateProxy>();
        return CHIP_NO_ERROR;
    }  

Proposed Solution

diff --git a/src/lib/dnssd/ResolverProxy.h b/src/lib/dnssd/ResolverProxy.h
index 88ac1d407..bd449ff50 100644
--- a/src/lib/dnssd/ResolverProxy.h
+++ b/src/lib/dnssd/ResolverProxy.h
@@ -68,7 +68,7 @@ public:
         ReturnErrorOnFailure(chip::Dnssd::Resolver::Instance().Init(inetLayer));
         VerifyOrReturnError(mDelegate == nullptr, CHIP_ERROR_INCORRECT_STATE);
         mDelegate = chip::Platform::New<ResolverDelegateProxy>();
-        return CHIP_NO_ERROR;
+        return mDelegate != nullptr ? CHIP_NO_ERROR : CHIP_ERROR_NO_MEMORY;
     }
 
     void SetResolverDelegate(ResolverDelegate * delegate) override
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 20, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 21, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 21, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 21, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 22, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 22, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 22, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 22, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 23, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 23, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 30, 2021
msandstedt added a commit to msandstedt/connectedhomeip that referenced this issue Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant