Are buffer overflow exploits possible in C#?

前端 未结 4 1224
礼貌的吻别
礼貌的吻别 2020-12-29 04:24

Assuming that a C# program uses only managed .NET code, is it possible to have a buffer overflow security vulnerability within that program? If so, how would such vulnerabil

4条回答
  •  清酒与你
    2020-12-29 04:43

    Yes, in unsafe environments:

    unsafe void bufferOverflow(string s)
    {
        char* ptr = stackalloc char[10];
    
        foreach (var c in s)
        {
            *ptr++ = c; // Bufferoverflow if s.Length > 10
        }
    }
    

    "Allow unsafe code" has to be checked for this to compile.

    You can't a traditional buffer-overflow with an array. It will do bounds-checking before accessing an array unless it (CLR) can guarantee it is safe.

提交回复
热议问题