Lazy init stringClass in ssl.c before using to avoid crashes #33
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.
I spent some time digging into the
SSL.getCiphers()test that caused the JVM to crash (following up on the dev-list thread mentioning it); I found that crashes occur when calling the method without first callingSSL.initialize(). The root cause is thatssl.candsslcontext.ceach declare their own staticstringClassvariable (ssl.c:43 and sslcontext.c:30). The variable inssl.cgets initialized only whenSSL.initialize()is called (ssl.c:221-223), butSSL.getCiphers()uses it directly without any NULL check (ssl.c:1104). In contrast,sslcontext.chandles this correctly:SSLContext.make()uses lazy initialization with a NULL check (sslcontext.c:410-415) before any method uses the variable.The crash occurs when code calls
SSLContext.make()(which initializesstringClassinsslcontext.cbut not inssl.c), then callsSSL.getCiphers()without having calledSSL.initialize()first. The method appears unused in Tomcat proper, so I think we have two options:sslcontext.c:410-414, which is what this PR doesFixing the issue is just a few added lines, and provides different information than
SSLContext.getCiphers()(per-connection negotiated ciphers vs context-level configured ciphers) so it may be useful to keep for any user that might want to do so in the future.