Marshal.SecureStringToBSTR and ZeroFreeBSTR not implemented for Unix
We have not implemented Marshal.SecureStringToBSTR for Unix.
https://github.com/dotnet/coreclr/blob/master/src/mscorlib/src/System/Runtime/InteropServices/Marshal.cs#L1775
This is bug/inconsistency. We have implemented BSTR on Unix, even though it is COM interopy. Mono took the same approach. We should remove the FEATURE_COMINTEROP ifdef around this one and make it work on Unix - to be consistent with other methods that take BSTRs.
Also Marshal.ZeroFreeBSTR can be implemented for Unix.
SecureStringToBSTR seems to have high usage on Xamarin. ZeroFreeBSTR has some usage, but small.
This is a nice to have for 2.0
cc @yizhang82
@botaberg Can you take a look?
I can take a look. Thanks!
@yizhang82 Is this issue still high-pri for 2.0? I know we talked about this for a bit offline, but I haven't gotten to implementing it yet.
@botaberg there is some usage, it's low but we've learned it's papercuts that break compat. Is there an idea of how much work this is? We should certainly do it if it's just a few lines. IMO.
It's low pri but I agree we should simply go do it. It's definitely a bit more than a few lines - we would need to:
- Enable SecureStringToBSTR for CoreCLR (it should just work).
- Add corresponding p/invokes for S.P.CoreLib as InteropExtension / ExternalInterop that points to Windows API on Windows and stub them out for non-windows
- (Nice to have) Add corresponding C# implementation for those p/invokes for non-Windows (basically porting coreclr/src/palrt/bstr.cpp to managed code).
- (Nice to have) Hook up those APIs to various Marshal.BSTR implementation for non-windows as well
This bug is specifically about Marshal.SecureStringToBSTR for CoreCLR. (1. in your list - it should be easy.)
Enabling BSTRs for CoreRT on Unix (2.-4. in your list) should be tracked in CoreRT repo with the rest of the interop porting work (https://github.com/dotnet/corert/issues/669).
@botaberg are you on track for this one? 2.0 should come beofre 2.1 work.
@botaberg is going to be back tomorrow. We should be able to get it in this week.
Fixed by https://github.com/dotnet/coreclr/pull/11234