The Stack Flashcards
To understand the fundamentals of the stack in Windows 32-bit architecture.
What is The Stack used for?
The Stack is used to allocate short-term storage for local function and method variables in an ordered manner. This memory is freed at the termination of each given function. During execution, each function is allocated its own stack frame on the Stack, which is deleted at the conclusion of a function.
What is a stack frame?
When a program executes, a stack frame is created to store its local variables. Each function gets its own stack frame, which is put on top of the current stack and causes the stack to grow upwards to lower addresses.
include
Describe the following function:
void foo(char *bar){ char c[12]; strcpy(c, bar); //no bounds checking }
int main(int argc, char **argv){ foo(argv[1]); }
The code calls the function foo() and passes it a single command line parameter (argv[1]). Function foo() then declares a variable of length 12, c, to hold the argv parameter. The strcpy() function is then used to copy the value of bar into variable c, during which no bounds checking is performed. This could resultantly lead to a buffer overflow.
What is ‘Little Endian’ WRT ‘Endianness’?
Endianness refers to the order in which bytes are stored in memory. In Intel x86 assembly architecture, the least significant byte of a value is stored at the smallest memory address. As such, the bytes are stored in reverse order.