-
Notifications
You must be signed in to change notification settings - Fork 518
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
[security] Add nullability to (generated and manual) bindings #14884
Conversation
src/Security/SslConnection.cs
Outdated
var c = (SslConnection) GCHandle.FromIntPtr (connection).Target; | ||
return c.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); | ||
var c = GCHandle.FromIntPtr (connection).Target as SslConnection; | ||
return c!.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this look okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the c! rather than doing an as, do an is, correct? Then you get the ! out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mandel-macaque if I do something like this:
if (GCHandle.FromIntPtr (connection).Target is SslConnection c)
return c.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength));
Then I am a little confused on what I should return if GCHandle.FromIntPtr (connection).Target is not SslConnection unless I should just throw an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think and invalid cast exception would be a good option https://docs.microsoft.com/en-us/dotnet/api/system.invalidcastexception?view=net-6.0 but we should ping @rolfbjarne
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is called from native code, so any exception is probably going to have rather disastrous consequences.
On the other hand, if this code fails, something disastrous already happened, so surfacing that disaster might be the best thing to do.
My vote goes for not changing the behavior (when in doubt, keep doing the same thing is usually the safest choice), so something like this:
var c = (SslConnection) GCHandle.FromIntPtr (connection).Target!;
return c.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength));
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
src/Security/SecProtocolMetadata.cs
Outdated
static sec_protocol_metadata_access_distinguished_names_handler_t static_DistinguishedNamesForPeer = TrampolineDistinguishedNamesForPeer; | ||
|
||
[MonoPInvokeCallback (typeof (sec_protocol_metadata_access_distinguished_names_handler_t))] | ||
static void TrampolineDistinguishedNamesForPeer (IntPtr block, IntPtr data) | ||
{ | ||
var del = BlockLiteral.GetTarget<Action<DispatchData>> (block); | ||
if (del != null) { | ||
var dispatchData = new DispatchData (data, owns: false); | ||
del (dispatchData); | ||
} | ||
} | ||
|
||
[DllImport (Constants.SecurityLibrary)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I agree with the re-indentation, yes. Does it make the review harder, yes. Can we do the reindentation after.
src/Security/SecProtocolMetadata.cs
Outdated
} | ||
|
||
[DllImport (Constants.SecurityLibrary)] | ||
static sec_protocol_metadata_access_supported_signature_algorithms_handler_t static_SignatureAlgorithmsForPeer = TrampolineSignatureAlgorithmsForPeer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
|
||
[BindingImpl (BindingImplOptions.Optimizable)] | ||
public void SetSignatureAlgorithmsForPeerHandler (Action<ushort> callback) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
src/Security/SslConnection.cs
Outdated
var c = (SslConnection) GCHandle.FromIntPtr (connection).Target; | ||
return c.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); | ||
var c = GCHandle.FromIntPtr (connection).Target as SslConnection; | ||
return c!.Read (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the c! rather than doing an as, do an is, correct? Then you get the ! out.
src/Security/SslConnection.cs
Outdated
var c = (SslConnection) GCHandle.FromIntPtr (connection).Target; | ||
return c.Write (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); | ||
var c = GCHandle.FromIntPtr (connection).Target as SslConnection; | ||
return c!.Write (data, ref System.Runtime.CompilerServices.Unsafe.AsRef<nint> (dataLength)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
This comment has been minimized.
This comment has been minimized.
@rolfbjarne @mandel-macaque Ready for re-review! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻✅ All tests on macOS Mac Catalina (10.15) passed. Pipeline on Agent |
📋 [PR Build] API Diff 📋API Current PR diffℹ️ API Diff (from PR only) (please review changes) View dotnet API diffView dotnet legacy API diffAPI diff✅ API Diff from stable View dotnet API diffView dotnet legacy API diffGenerator diff✅ Generator Diff (no change) Pipeline on Agent XAMBOT-1100.Monterey' |
❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌Failed tests are:
Pipeline on Agent |
❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌Tests failed on VSTS: simulator tests iOS. Test results22 tests failed, 126 tests passed.Failed tests
Pipeline on Agent XAMBOT-1096.Monterey |
Merging since the test failures are unrelated timeouts! |
This PR aims to bring nullability changes to Security.
Following the steps here:
nullable enable
to all manual files that are not "API_SOURCES" in src/frameworks.sources and making the required nullability changesthrow new ArgumentNullException ("object"));
toObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (object));
for size saving optimization as well to mark that this framework contains nullability changes== null
or!= null
tois null
andis not null