- Memory safety
Memory safety is a concern in software development that aims to avoid software bugs that cause security vulnerabilities dealing with random-access memory (RAM) access, such as buffer overflows and dangling pointers.
Computer languages such as C and C++ that support arbitrary pointer arithmetic, casting, and deallocation are typically not memory safe
Types of memory errors
Buffer overflow - Out-of bound writes can corrupt the content of adjacent objects, or internal data like bookkeeping information for the heap or return addresses.
Dynamic memory errors - Incorrect management of dynamic memory and pointers:
Dangling pointer - A pointer storing the address of an object that has been deleted.
Double frees - Repeated call to free though the object has been already freed can cause freelist-based allocators to fail.
Invalid Free - Passing an invalid address to free can corrupt the heap. Or sometimes will lead to an undefined behavior.
Null pointer accesses will cause an exception or program termination in most environments, but can cause corruption in operating system kernels or systems without memory protection, or when use of the null pointer involves a large or negative offset.
Uninitialized variables - A variable that has not been assigned a value is used. It may contain an undesired or, in some languages, a corrupt value.
Wild pointers arise when a pointer is used prior to initialization to some known state. They show the same erratic behaviour as dangling pointers, though they are less likely to stay undetected.
Out of memory errors:
Stack overflow - Occurs when a program runs out of stack space, typically because of too deep recursion.
Allocation failures - The program tries to use more memory than the amount available. In some languages, this condition must be checked for manually after each allocation.
Buffer overflow
A buffer is a temporary data storage area. Buffer overflow is the most common way for an attacker outside the system to gain unauthorized access to the target system. A buffer overflow occurs when a program tries to store more data in a buffer than it was intended to hold. Since buffers are created to contain a finite amount of data, the extra information can overflow into adjacent buffers, corrupting or overwriting the valid data held in them.It allows attacker to interfere into the existing process code. Attacker uses buffer or stack overflow to do following,
Overflow the input field, command line space or input buffer.
Overwrite the current return address on the stack with the address of the attacking code.
write a simple code that attacker wishes to execute.
http://en.wikipedia.org/wiki/Memory_safety