Mitigate strange segfault in tests/client012.phpt #81
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.
Building on debian stretch against libcurl4-openssl-dev 7.52.1-5+deb9u6 (current) I get a segfault in this test. I have been unable to reproduce it in any other environment, so I assume it is a problem with one of the dependencies rather than this extension (probably openssl, as you will see in a minute) - however it can be mitigated in the extension.
Digging into it, the problem is that
SSL_get_SSL_CTX()is returning garbage - it always seems to return0x19000- which results in a segfault when the pointer is dereferenced further down. However, if I switch to the pre-7.48 branch (i.e. useCURLINFO_TLS_SESSIONinstead ofCURLINFO_TLS_SSL_PTR) then I get a valid pointer, the data is retrieved correctly, the test passes and there is no segfault. I cannot see any obvious problem with the code in theCURLINFO_TLS_SSL_PTRbranch, I can only assume it is an upstream bug - although I cannot find any similar reports against libcurl or openssl either.Since no following code actually requires the
SSL*handle, I propose switching to always useCURLINFO_TLS_SESSIONand accessing theSSL_CTX*handle directly. This would be a simplification of the code, and avoids this issue. If a future feature requires theSSL*handle... well, we can cross that bridge when we come to it 😛For reference, here's the valgrind details of the issue: