我正在尝试使用 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/