Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure networkBio is closed in ConscryptEngine. #942

Merged
merged 3 commits into from
Jan 22, 2021

Conversation

prbprbprb
Copy link
Collaborator

Contains @kruton's PR #893 plus my comments.

Differences:

Throw SslException not SocketException on read and write to
closed ssl as these will propogate out from SSLEngine.wrap()
(and unwrap).

Calls closeAndFreeResources() from ConscryptEngine.finalizer()
which should ensure resources are consistently freed even if engines
aren't properly closed.

closeAndFreeResources() handles null ssl or networkBio - because
it is called from the finalizer it must handle incompletely constructed
instances. Also closes networkBio regardless of whether ssl is
closed in case the engine ever gets into this state (e.g. if close()
throws). Both close methods are idempotent.

Contrary to my suggestion, no check for bio == 0L on read and write
because native code will already throw NullPointerException for that
which seems correct.

Contains @kruton's PR google#893 plus my comments.

Differences:

Throw `SslException` not `SocketException` on read and write to
closed `ssl` as these will propogate out from `SSLEngine.wrap()`
(and unwrap).

Calls `closeAndFreeResources()` from `ConscryptEngine.finalizer()`
which should ensure resources are consistently freed even if engines
aren't properly closed.

`closeAndFreeResources()` handles null `ssl` or `networkBio` - because
it is called from the finalizer it must handle incompletely constructed
instances.  Also closes `networkBio` regardless of whether `ssl` is
closed in case the engine ever gets into this state (e.g. if `close()`
throws).  Both close methods are idempotent.

Contrary to my suggestion, no check for `bio == 0L` on read and write
because native code will already throw `NullPointerException` for that
which seems correct.
@prbprbprb prbprbprb merged commit 7682a17 into google:master Jan 22, 2021
@prbprbprb prbprbprb deleted the bio_close branch January 22, 2021 14:41
@prbprbprb prbprbprb mentioned this pull request Feb 1, 2021
prbprbprb added a commit that referenced this pull request Feb 25, 2021
Ensure networkBio is closed in ConscryptEngine.
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.

2 participants