Search code examples
c++stackcorruption

Stack corruption in C++


In C++, in which way can the stack get corrupted? One way I guess is to overwrite the stack variables by accessing an array beyond its boundaries. Is there any other way that it can get corrupted?


Solution

    1. You could have a random/undefined pointer that ends up pointing to the stack, and write though that.
    2. An assembly function could incorrectly setup/modify/restore the stack
    3. Cosmic waves could flips bits in the stack.
    4. Radioactive elements in the chip's casing could flip bits.
    5. Anything in the kernel could go wrong and accidentally change your stack memory.

    But those are not particular to C++, which doesn't have any idea of the stack.