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

[security] Add nullability to (generated and manual) bindings #14884

Merged
merged 9 commits into from
May 12, 2022

Conversation

tj-devel709
Copy link
Contributor

This PR aims to bring nullability changes to Security.
Following the steps here:

  1. I am adding nullable enable to all manual files that are not "API_SOURCES" in src/frameworks.sources and making the required nullability changes
  2. Changing all throw new ArgumentNullException ("object")); to ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (object)); for size saving optimization as well to mark that this framework contains nullability changes
  3. Changing any == null or != null to is null and is not null

@tj-devel709 tj-devel709 added the not-notes-worthy Ignore for release notes label May 3, 2022
@tj-devel709 tj-devel709 added this to the Future milestone May 3, 2022
@tj-devel709 tj-devel709 requested a review from dalexsoto as a code owner May 3, 2022 18:27
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));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this look okay?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Member

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));

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Comment on lines 206 to 218
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)]
Copy link
Member

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.

}

[DllImport (Constants.SecurityLibrary)]
static sec_protocol_metadata_access_supported_signature_algorithms_handler_t static_SignatureAlgorithmsForPeer = TrampolineSignatureAlgorithmsForPeer;
Copy link
Member

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)
{
Copy link
Member

Choose a reason for hiding this comment

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

Same.

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));
Copy link
Member

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.

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));
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@tj-devel709
Copy link
Contributor Author

@rolfbjarne @mandel-macaque Ready for re-review!

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

💻 [PR Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: be668c7319d8788f7dc0a5fea65e4f36fb5d23c6

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent XAMBOT-1039.Monterey'
Hash: be668c7319d8788f7dc0a5fea65e4f36fb5d23c6

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📋 [PR Build] API Diff 📋

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

Generator Diff (no change)

Pipeline on Agent XAMBOT-1100.Monterey'
Hash: be668c7319d8788f7dc0a5fea65e4f36fb5d23c6

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [PR Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • dontlink
  • linksdk
  • linkall

Pipeline on Agent
Hash: be668c7319d8788f7dc0a5fea65e4f36fb5d23c6

@vs-mobiletools-engineering-service2
Copy link
Collaborator

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

22 tests failed, 126 tests passed.

Failed tests

  • link sdk/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 107 Inconclusive: 0 Failed: 2 Ignored: 8)
  • link sdk/Mac [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 106 Inconclusive: 0 Failed: 2 Ignored: 9)
  • link sdk/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 119 Inconclusive: 0 Failed: 2 Ignored: 8)
  • link sdk/Mac Catalyst [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 119 Inconclusive: 0 Failed: 1 Ignored: 9)
  • link sdk/Mac Modern/Debug: Failed (Test run failed.
    Tests run: 9 Passed: 8 Inconclusive: 0 Failed: 1 Ignored: 0)
  • link sdk/iOS Unified 64-bits - simulator/Debug [dotnet]: Failed
  • link sdk/iOS Unified 64-bits - simulator/Release [dotnet]: Failed
  • link sdk/iOS Unified 64-bits - simulator/Debug: Failed
  • link sdk/iOS Unified 64-bits - simulator/Release: Failed
  • link sdk/tvOS - simulator/Debug [dotnet]: Failed
  • link sdk/tvOS - simulator/Release [dotnet]: Failed
  • link sdk/tvOS - simulator/Debug: Failed
  • link sdk/tvOS - simulator/Release: Failed
  • trimmode link/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 107 Inconclusive: 0 Failed: 2 Ignored: 8)
  • trimmode link/Mac [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 117 Passed: 107 Inconclusive: 0 Failed: 1 Ignored: 9)
  • trimmode link/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 120 Inconclusive: 0 Failed: 1 Ignored: 8)
  • trimmode link/Mac Catalyst [dotnet]/Release [dotnet]: Failed (Test run failed.
    Tests run: 129 Passed: 118 Inconclusive: 0 Failed: 2 Ignored: 9)
  • trimmode link/iOS Unified 64-bits - simulator/Debug [dotnet]: Failed
  • trimmode link/iOS Unified 64-bits - simulator/Release [dotnet]: Failed
  • trimmode link/tvOS - simulator/Debug [dotnet]: Failed
  • trimmode link/tvOS - simulator/Release [dotnet]: Failed
  • link all/Mac Modern/Debug: Failed (Test run failed.
    Tests run: 20 Passed: 18 Inconclusive: 0 Failed: 1 Ignored: 1)

Pipeline on Agent XAMBOT-1096.Monterey
Merge be668c7 into 1be1d74

@tj-devel709
Copy link
Contributor Author

Merging since the test failures are unrelated timeouts!

@tj-devel709 tj-devel709 merged commit fcf1a19 into xamarin:main May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not-notes-worthy Ignore for release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants