Задайте вопросЗадайте вопрос
 

ОтвеченоC++/CLI C++ Interop and FxCop/Code-Analysis warning CA2122

  • 12 сентября 2006 г. 15:52Peter RitchieMVP, МодераторМедали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    I've purposely been ignoring a CA2122 warning in some C++ interop code I've been working on for quite some time.  I've just recently had the cycles to investigate the warning  The warning message is as follows

    Warning CA2122 : Microsoft.Security : MyClass.Method():Void calls into Marshal.GetExceptionPointers():IntPtr which has a LinkDemand. By making this call, Marshal.GetExceptionPointers():IntPtr is indirectly exposed to user code. Review the following call stack that might expose a way to circumvent security protection:
    ->System.Runtime.InteropServices.Marshal.GetExceptionPointers : IntPtr
    ->MyClass.Method : Void
    ...

    MyClass is a managed class where Method calls a native static (for readable illustration purposes only) function; where the code is as follows:

    static void MethodImplementation() throw(std::runtime_error &)

    {

        //...

        throw std::runtime_error("a message");

        //...

    }

     

    //...

    void MyClass::Method()

    {

        try

        {

            return MethodImplementation();

        }

        catch(std::runtime_error &)

        {

            //...

        }

    }

    My concern isn't that FxCop/Code-Analysis is pumping out this message, it's the LinkDemand that catch(std::runtime_error) is forcing upon this method.

    Assume for a moment that the method MethodImplementation is not within my control (cannot modify it) and it can obviously throw an std::runtime_error reference.  While I can add a LinkDemand attribute to the Method method, strong-name its assembly, and either throw that assenbly in the GAC or manually give it FullTrust and the implications of this LinkDemand go away; but I don't think I should need to.  There's are some architectural and policy issues to simply going FullTrust to swallow the "inherited" security demands of the Method method (like APTC); but this should all be an implementation detail, and the abstraction of C++ interop has leaked through to my implementation.

    Any thoughts?

Ответы

  • 6 ноября 2006 г. 1:59Peter RitchieMVP, МодераторМедали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     Отвечено
    Ayman is pretty good at keeping track of these things; but, there hasn't been a decision made on it that I've been made aware of (otherwise I would have added a comment of some sort).  I feel like it's a couple of issues myself.  The more important issue is that the C/C++ compiler is generating code that requires a LinkDemand even though it's within an UnmanagedCode permission context.  Getting rid of that (by pushing the LinkDemand into a system DLL and wrapping it with an assert) would get around the warning.  The other issue is the warning, some feel the warning about a call to a method with a LinkDemand for UnmanagedCode shouldn't be raised when the assembly has a SecurityPermission attribute for UnmanagedCode.  In this case the assembly has [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)] and there is still a warning that GetExceptionPointers has a LinkDemand for UnmanagedCode...  I've sent a fresh ping about the issue and I'll post any pertinent (disclosable) information.

Все ответы