Repository navigation
ssl: raise IOError in #ssl_read and #ssl_write if the IO is closed - #1165
Open
sourya2704 wants to merge 1 commit into
Open
sourya2704 wants to merge 1 commit into
sourya2704 wants to merge 1 commit into
Conversation
The C implementation of SSLSocket#sysread and #syswrite used to check the underlying IO with GetOpenFile(), which raises IOError if it has been closed. That check went away when the blocking methods were moved to Ruby, so after IO#close, SSL_write() kept using the old file descriptor number. If a new socket got the same number, the TLS record was written to it. Check that the underlying IO is still open before calling SSL_read() or SSL_write().
This branch has not been deployed
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.
Fixes #1156.
Before #1105,
SSLSocket#sysreadand#syswritecalledGetOpenFile()on the underlying IO, which raisesIOErrorif it has been closed. That check went away when the blocking methods moved to Ruby, so afterIO#closeon the underlying socket,SSL_write()kept using the old file descriptor number. With the reproduction from #1156, the record is written to a new socket that happens to get the same number:This adds the same check at the start of
#ssl_readand#ssl_write, so both the blocking and non-blocking methods raiseIOError: closed stream, as they did before #1105.sysreadalready raised in this case through the wait path, but#ssl_readnow checks directly as well.#1106 tracks the closed state of the
SSLSocketitself, and mentions that the underlying socket may be closed directly withIO#close. This covers that case, so the two don't overlap.The new test closes the underlying
TCPSocketand checks thatsyswriteandsysreadraiseIOError. It fails without the change.