Skip to content

Conversation

@rhenium
Copy link
Member

@rhenium rhenium commented Dec 7, 2025

The errno reported in OpenSSL::SSL::SSLError message sometimes does not match what SSL_accept()/SSL_connect() actually encountered. Depending on the evaluation order of function arguments to ossl_raise(), it can be overwritten by peeraddr_ip_str().

Save errno into a local variable immediately after the OpenSSL function returns, and avoid touching the thread-local errno afterward.

Also, expand rb_sys_fail() and rb_io_maybe_wait_{readable,writable}() so that they do not rely on errno.

@rhenium rhenium force-pushed the ky/ssl-errors-peeraddr-errno branch 2 times, most recently from 1f128c3 to 74d6b09 Compare December 7, 2025 17:22
The errno reported in an OpenSSL::SSL::SSLError raised by
SSLSocket#accept and #connect sometimes does not match what SSL_accept()
or SSL_connect() actually encountered. Depending on the evaluation order
of arguments passed to ossl_raise(), errno may be overwritten by
peeraddr_ip_str().

While we could just fix peeraddr_ip_str(), we should avoid passing
around errno since it is error-prone. Replace rb_sys_fail() and
rb_io_{maybe_,}wait_{read,writ}able() with equivalents that do not read
errno.
Remove an unnecessary instance variable lookup and constant lookup.
Ruby's public headers provide rb_eSystemCallError.
@rhenium rhenium force-pushed the ky/ssl-errors-peeraddr-errno branch from 74d6b09 to 46c9223 Compare January 23, 2026 16:18
@rhenium rhenium merged commit d2e1e9a into ruby:master Jan 23, 2026
48 checks passed
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 this pull request may close these issues.

1 participant