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

Unchecked Null Dereference which might cause Null pointer exception #3490

Open
abdullahil-kafi opened this issue Oct 29, 2024 · 0 comments
Open

Comments

@abdullahil-kafi
Copy link

Summary

In file InvocationContainerImpl.java line 87 answer(invocation) method is called on the return value of findAnswerFor(invocation). The method findAnswerFor(invocation) might return null but no null check is performed on the returned value inside the answerTo method which might cause null pointer exception. Here's the affected code snippet:

    Object answerTo(Invocation invocation) throws Throwable {
        return findAnswerFor(invocation).answer(invocation);
    }

    public StubbedInvocationMatcher findAnswerFor(Invocation invocation) {
        synchronized (stubbed) {
            for (StubbedInvocationMatcher s : stubbed) {
                if (s.matches(invocation)) {
                    s.markStubUsed(invocation);
                    // TODO we should mark stubbed at the point of stubbing, not at the point where
                    // the stub is being used
                    invocation.markStubbed(new StubInfoImpl(s));
                    return s;
                }
            }
        }

        return null;
    }

The static analysis was ran on version: v4.11.0

Sponsorship and Support

This work is done by the security researchers from OpenRefactory and is supported by the Open Source Security Foundation (OpenSSF): Project Alpha-Omega. Alpha-Omega is a project partnering with open source software project maintainers to systematically find new, as-yet-undiscovered vulnerabilities in open source code - and get them fixed - to improve global software supply chain security.

The bug is found by running the Intelligent Code Repair (iCR) tool by OpenRefactory and then manually triaging the results.

@abdullahil-kafi abdullahil-kafi changed the title Unchecked Null Dereference Bug which might cause Null dereference exception Unchecked Null Dereference which might cause Null pointer exception Oct 29, 2024
Miguel-Graham added a commit to Miguel-Graham/mockito that referenced this issue Nov 14, 2024
…nContainerImpl by adding null check for findAnswerFor` method
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

No branches or pull requests

1 participant