English 中文(简体)
制止腐败检查方法
原标题:stack corruption checking method

1) how to initialize the stack with some unique pattern? so i can check it on the exit? sample program plz 2) how to add values in prolog and check it in epilog ? sample program plz

  • valgrind and electric fence doesnt work with my multithreaded app it is too bulky i want some simple trick like
  • add const value in prolog
  • check it back in epilog

thanks, Vj

问题回答

In your first question I think you are talking about preventing the execution stack from being overran. There are different technique to archive this, but I think the one closest to "some unique pattern" is the canary.

Theory:
The canary is a (random) check value that is placed just below the functions return address. Before returning from the function, the system checks if the canary has the same value as before. If not, the stack has been overran, since the memory is written from lower to higher addresses, and you can t trust the return address.

How it s done:

  1. When the return address are placed on the stack, the canary is placed there as well.
  2. When the function exits, the canary is checked. If the canary has been altered, terminate the program (or whatever you find appropriate).

More information about canary values can be found here.
This (or some other stack overrun prevention technique) are generally implemented in modern compilers.

I have no idea about your second question.





相关问题
Having many stacks with different types

I m making a C program that needs to use two stacks. One needs to hold chars, the other needs to hold doubles. I have two structs, node and stack: struct node { double value; struct node *...

定型语言是否具有范围概念?

定型语言是否具有范围概念? 在我看来,如果职能参数被放在职能执行之前的位置上,这些参数就会以不正统的方式出现。

Stack memory fundamentals

Consider this code: char* foo(int myNum) { char* StrArray[5] = {"TEST","ABC","XYZ","AA","BB"}; return StrArray[4]; } When I return StrArray[4] to the caller, is this supposed to work? ...

negative number in the stack

I am a new student in the compilers world ^_^ and I want to know is legal represent negative number in the stack. For example: infix: 1-5=-4 postfix: 15- The statements are: push(1) push(5) x=...

热门标签