Avoid unsafe blocks

このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。

Metadata

ID: csharp-security/avoid-unsafe

Language: C#

Severity: Notice

Category: Security

Description

Avoid unsafe code blocks as much as possible. While unsafe blocks provide access to some important features of the C# language, you need to avoid using them as much as possible. For example, unsafe code allows developers to use pointers, but pointers and pointers arithmetic can lead to critical security issues. Unsafe code should be avoided or at least clearly identified in a small scope.

Learn More

Non-Compliant Code Examples

using System.IO;
using System.Security.Cryptography;

class MyClass {
    public void myMethod
    {
        unsafe{
            // statements
        }
       
    }
}
using System.IO;
using System.Security.Cryptography;

class MyClass {
    public unsafe void myMethod
    {
       // statements
    }
}

Compliant Code Examples

using System.IO;
using System.Security.Cryptography;

class MyClass {
    public void myMethod
    {
       // statements
    }
}
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis