runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Marshal.SecureStringToBSTR and ZeroFreeBSTR not implemented for Unix

Open danmoseley opened this issue 9 years ago • 12 comments

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.

danmoseley avatar Mar 24 '17 02:03 danmoseley

SecureStringToBSTR seems to have high usage on Xamarin. ZeroFreeBSTR has some usage, but small.

danmoseley avatar Mar 24 '17 17:03 danmoseley

This is a nice to have for 2.0

danmoseley avatar Mar 24 '17 17:03 danmoseley

cc @yizhang82

jkotas avatar Mar 27 '17 17:03 jkotas

@botaberg Can you take a look?

yizhang82 avatar Mar 27 '17 17:03 yizhang82

I can take a look. Thanks!

botaberg avatar Mar 27 '17 17:03 botaberg

@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 avatar Apr 15 '17 00:04 botaberg

@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.

danmoseley avatar Apr 17 '17 18:04 danmoseley

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

yizhang82 avatar Apr 18 '17 06:04 yizhang82

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

jkotas avatar Apr 18 '17 11:04 jkotas

@botaberg are you on track for this one? 2.0 should come beofre 2.1 work.

danmoseley avatar Apr 25 '17 05:04 danmoseley

@botaberg is going to be back tomorrow. We should be able to get it in this week.

yizhang82 avatar Apr 25 '17 06:04 yizhang82

Fixed by https://github.com/dotnet/coreclr/pull/11234

danmoseley avatar May 02 '17 20:05 danmoseley