crypto: add NULL check for SSL_new() result in SSLPointer::New#62819
Open
Jah-yee wants to merge 1 commit intonodejs:mainfrom
Open
crypto: add NULL check for SSL_new() result in SSLPointer::New#62819Jah-yee wants to merge 1 commit intonodejs:mainfrom
Jah-yee wants to merge 1 commit intonodejs:mainfrom
Conversation
Add explicit NULL check for SSL_new() return value in SSLPointer::New(), consistent with the pattern used by CipherCtxPointer::New(). Fixes a potential NULL pointer dereference when OpenSSL fails to allocate an SSL structure under memory pressure (Coverity CID 15826735). Fixes: nodejs#62774
Collaborator
|
Review requested:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Good day
This PR addresses a potential NULL pointer dereference identified by static analysis (Svace) in the OpenSSL allocation functions.
Problem
In
deps/ncrypto/ncrypto.cc, theSSLPointer::New()function callsSSL_new()and passes its result directly to theSSLPointerconstructor without checking if the allocation failed:return SSLPointer(SSL_new(ctx.get()));If OpenSSL fails to allocate an SSL structure (e.g., under memory pressure),
SSL_new()returns NULL, which would then be stored in theSSLPointerand potentially dereferenced later, causing a segmentation fault.Solution
Added an explicit NULL check after
SSL_new(), consistent with the pattern already used byCipherCtxPointer::New()in the same file:Testing
The change follows the established pattern in the codebase and does not alter any existing behavior for the success case. Callers of
SSLPointer::New()already check the returned value (e.g.,if (!ssl)), so they will properly handle the NULL case after this fix.Related Issue
Fixes #62774
Thank you for your attention. If there are any issues or suggestions, please leave a comment and I will address them promptly.
Warmly,
RoomWithOutRoof