我正在准备C中的一些培训材料,我希望我的示例适合典型的堆栈模型.
C堆栈在Linux,Windows,Mac OSX(PPC和x86),Solaris和最新的Unix中的发展方向是什么?
这与"为什么堆栈通常会向下生长?"这个问题有关.,但从安全的角度来看更多.我通常指的是x86.
当缓冲区通常在内存中向上写入时,堆栈会向下增长,这让我觉得很奇怪.例如,典型的C++字符串的结尾位于比开头更高的内存地址.
这意味着如果存在缓冲区溢出,则会进一步覆盖调用堆栈,我理解这是一种安全风险,因为它可以更改返回地址和本地变量内容.
如果堆栈在内存中向上增长,那么缓冲区溢出会不会简单地运行到内存中?这会提高安全性吗?如果是这样,为什么还没有这样做?那么x64,那些堆栈是否会增长,如果不是,为什么不呢?
我是装配新手,然后我遇到了这篇文章
它说这个代码
void MyFunction()
{
int a, b, c;
a = 10;
b = 5;
c = 2;
Run Code Online (Sandbox Code Playgroud)
相当于此
push ebp ; save the value of ebp
mov ebp, esp ; ebp now points to the top of the stack
sub esp, 12 ; space allocated on the stack for the local variables
mov [ebp - 4], 10 ; location of variable a
mov [ebp - 8], 5 ; location of b
mov [ebp - 12], 2 ; location …Run Code Online (Sandbox Code Playgroud) stack ×3
assembly ×2
stack-frame ×2
abi ×1
architecture ×1
callstack ×1
cpu ×1
masm ×1
security ×1
x86 ×1