buffer/stack overflow Flashcards
what is a buffer
a limited, contiguously allocated set of memory used for data storage
> buffer can be on stack, heap, global data
what is buffer overflow
occurs when a program writes more data into a buffer (a temporary storage area in memory) than the buffer can hold. this typically happens when input data is not properly validated or sanitized.
what is a stack
a data structure that follows Last-In-First-Out principle with two primary operations
> push: add element at the top
> pop: remove element at the top
as more data is added to the stack, the address values become lower
what is a stack overflow
occurs when the call stack (a region of memory used to manage function calls and local variables) becomes full because of too many nested function calls or recursive calls without proper termination conditions
what is a stack pointer
a register that keeps track of the location or address of the top of the call stack and defines the stack’s boundary
what does the POP instruction do to the stack pointer
only changes the pointer’s value, it does not write or erase data from the stack
what is the base pointer register
it is used to calculate the address of variables relative to the address of a reference point/base address
gets(char *str)
read line from standard input into str
strcat(char *dest, char *src)
appends src to dest (concatenate)
strcpy(char *dest, char *src)
copies content of src to dest
sprintf(char *str, char *format)
create a str according to the supplied format
what happens when a function call is made
- for each function, a stack frame will be created
- stack frame will have: return address of caller, input params, local variables
describe the IA-32 stack frame
- it grows downwards
so from higher address values to lower address values - ESP is at the bottom (lower value address)
the calling convention in the stack frame
CALLER method
1. push parameters in order from last to first
2. push object instance
3. call method
CALLEE method
4. save registers on stack
5. execute body of method
6. copy results into eax
7. restore registers from stack
8. return from method
BACK TO CALLER
9. remove object instance from the stack
10. remove parameters from the stack
saving and restoring registers
> is done by the callee method
e.g.: two registers: edi and ecx
save registers:
push ecx;
push edi;
restore registsers
pop edi;
pop ecx;