What is different between stack overflow and buffer overflow in Programming ?
Stack overflow refers specifically to the case when the execution stack grows beyond the memory that is reserved for it. For example, if you call a function which recursively calls itself without termination, you will cause a stack overflow as each function call creates a new stack frame and the stack will eventually consume more memory than is reserved for it.
Buffer overflow refers to any case in which a program writes beyond the end of the memory allocated for any buffer (including on the heap, not just on the stack). For example, if you write past the end of an array allocated from the heap, you've caused a buffer overflow.
A stackoverflow is when the size of the stack for a thread exceeds the maximum allowable stack size for that thread.
A buffer overflow is when a value is written into memory that is not currently allocated by the program.
Stack overflow: you have put too many things on the stack for the memory allocated to the current thread
Buffer overflow: You have exceeded the size of your currently allocated buffer and have not resized it to fit (or cannot resize it further).
Buffer overflow usually stands for anytime a memory buffer is accessed beyond it's bounds whether stack or heap. A stack overflow means the stack has exceed it's allocated limit and on most machines/OS is running over heap.
The key difference is knowing the difference between the stack and a buffer.
The stack is the space reserved for the executing program to execute in. When you call a function, it's parameter and return info are placed on the stack.
A buffer is a generic chunck of memory that is used for a single purpose. For example, a string is a buffer. It can be over run by writing more data to the string than was allocated for.
Don't you mean to say "what is the difference between a stack and a buffer?" -- that will lead you to more insight more quickly. Once you've gotten that far, then you can think about what it means to overflow each of these things.