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

fix(bindings): make Context borrow immutable #5071

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jmayclin
Copy link
Contributor

@jmayclin jmayclin commented Jan 30, 2025

Release Summary:

A breaking change was made to the renegotiation callback interface. This only affects Rust customers using the unstable-renegotiate feature.

Description of changes:

with_context is invoked as part of callbacks. Callbacks are set on configs, and as such may be invoked concurrently. Therefore it is not valid to hold a &mut to the Context. This PR updates with_context to use an immutable ref.

We weren't actually using the context as mutable anywhere, so for most callbacks this is not a breaking change.

For the renegotiate callback, this is a breaking change. Although this is not expected to significantly change the feature. From the PR, it can be observed that the feature still works largely the same even with the type signature change.

Testing:

All tests should continue to pass.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jmayclin jmayclin requested a review from lrstewart January 30, 2025 01:22
@jmayclin jmayclin requested a review from camshaft January 30, 2025 02:00
@jmayclin jmayclin changed the title fix(bindings)!: make Context borrow immutable fix(bindings): make Context borrow immutable Jan 30, 2025
{
let raw = NonNull::new(conn_ptr).expect("connection should not be null");
let mut conn = Connection::from_raw(raw);
let mut config = conn.config().expect("config should not be null");
let context = config.context_mut();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the context_mut method entirely? It should really only be used during the builder. If it's on the config, it's too easy to call. Or at the very least mark it unsafe.

* make context_mut unsafe
@jmayclin jmayclin requested a review from camshaft February 1, 2025 04:03
@jmayclin
Copy link
Contributor Author

jmayclin commented Feb 6, 2025

I didn't expect that there was a copy-pasted context_mut() implementation on the Builder. The latest revision addresses that.

@@ -334,7 +338,12 @@ impl Builder {
)
.into_result()
};
self.context_mut().application_owned_certs.push(chain);
let context = unsafe {
Copy link
Contributor Author

@jmayclin jmayclin Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copy pastes are a bit tedious, but I did it this way to try and prevent anyone from passing a mut_context in as the context parameter of the s2n callback.

Practically it doesn't make a difference because the pointer isn't actually treated as mut, but it would be very dangerous if it were, so the extra friction seemed warranted? Let me know if folks prefer it to just be a method on the Builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants