C# 创建缓冲区溢出

标签 c# overflow buffer unsafe

我正在尝试使用 C# 为学校项目创建缓冲区溢出:

unsafe
{
    fixed (char* ptr_str = new char[6] {'H', 'a', 'l', 'l', 'o', ','})
    {
        fixed (char* ptr_str2 = new char[6] {'W', 'e', 'r', 'e', 'l', 'd'})
        {
            fixed (char* ptr_str3 = new char[6] {'!', '!', '!', '!', '!', '!'})
            {
                for (int i = 0; i < 8; i++)
                {
                    ptr_str2[i] = 'a';
                }

                for (int i = 0; i < 6; i++)
                {
                    this.Label2.Text += ptr_str[i];
                    this.Label3.Text += ptr_str2[i];
                    this.Label4.Text += ptr_str3[i];
                }
            }
        }
    }
}

我认为这会淹没 ptr_str2,从而覆盖 ptr_str 中的字符。然而,这似乎并没有发生。它会执行,但 ptr_str 中的值不会被覆盖。

任何人都可以帮助实现这一目标吗?我不明白我做错了什么。

最佳答案

Stack overflow是调用栈的溢出。 做起来容易得多:

int Test ()
{
    return Test ();
}

Console.WriteLine (Test ());

如果您的意思是缓冲区溢出,则有一个similar question .

关于C# 创建缓冲区溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4906801/

相关文章:

c# - C# 中的通用缓冲区 [Java 中的示例]

c# - C# linq 和 ORACLE 对点顺序的不同解释

c# - WPF:PropertyChangedCallback 只触发一次

Android 支持操作栏不显示溢出菜单

css - 如何在带有 overflow hidden 的父级内部水平居中放置多个图像

c - 缓冲区溢出 - 为什么有些 ASCII 可以工作,而另一些则不行

c# - 强制刷新到 Observable.Buffer c#

c# - FileDialog.RestoreDirectory 属性实际上做了什么?

c# - 跨页发布 GridView

html - Angular 8中根据是否有overflow-x(水平滚动)显示和隐藏元素