本机调用调用的Fortify问题

问题描述 投票:0回答:2

我有一个utils类,其中我有许多静态方法,在同一个类中我有一个Native调用声明,如下所示。

[System.Runtime.InteropServices.DllImport("kernel32.dll")]
internal static extern bool Beep(int freq, int duration);

因此,我得到了“不安全的本机调用”,其中静态方法被调用,当我删除上述声明并放置在另一个名为NativeMethods的类中时,它已经清除了所有问题。

但问题是为什么我们为自己的静态方法得到“不安全的本机调用”问题?

c# native fortify
2个回答
1
投票

将原生调用移动到* NativeMethods类是Microsoft Code Analysis design check(CA1060)The Fortify documentation for this vulnerability引用了Microsoft文档How to: Call Native DLLs from Managed Code Using PInvoke

它可以标记这些本机调用,无论这些调用是否由您拥有(它不知道这一点)。


0
投票

将本机调用移动到私有struct / class可以解决此问题。

private struct SecureNativeMethods
{
    [System.Runtime.InteropServices.DllImport("kernel32.dll")]
    internal static extern bool Beep(int freq, int duration);
}

并使用SecureNativeMethods.Beep(..)调用该方法

© www.soinside.com 2019 - 2024. All rights reserved.