The countermeasures to a buffer overflow are as follows:
* Perform manual auditing of the code.
* Stack execution should be disabled.
* Take the support of the functions which are not the cause of the buffer overflow.
*
* Take compiler support. For example, Java automatically checks if an array index is within the proper bounds. Use compilers such as Java instead of C to avoid buffer overflow attacks. Use tools such as StackGuard and Immunix System to avoid buffer overflows.