栈的原理和缓冲区溢出原理

本文的目的是读完本文及参考文献后基本理解什么是栈,C语言函数调用过程中栈的变化,以及缓冲区溢出原理。

基本知识

  • Stack(栈) is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle. In the pushdown stacks only two operations are allowed: push the item into the stack, and pop the item out of the stack. A stack is a limited access data structure - elements can be added and removed from the stack only at the top. push adds an item to the top of the stack, pop removes the item from the top [1].
  • Stack Frame(栈帧) is the collection of all data on the stack associated with one subprogram call. The stack frame generally includes: the return address, the argument variables passed on the stack, local variables and the saved copies of any registers modified by the subprogram that need to be restored [2].
  • EBP(帧指针) is the base pointer for the current stack frame [3].
  • ESP(栈指针) is the current stack pointer [3].
  • 每次调用函数时,生成一个新的栈帧,存放于栈的某段空间中。EBP总是指向栈帧的顶部(高地址),而ESP指向栈中的下一个可用字节。EBP在函数执行期间不发生变化,而ESP随着函数执行是变化的[3]。

函数调用过程中栈的变化

请参考以下两篇文献:

缓冲区溢出原理

请参考以下两篇文献:

其它参考文献:
[1] Stacks and Queues
[2] The Stack Frame
[3] What is between ESP and EBP?

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值