Buffer overflow
A buffer overflow occurs when a program or process tries to store more data in a buffer(temporary data storage area) than it was intended to hold.
A buffer overflow occurs when data written to a buffer, due to insufficient bounds checking, corrupts data values in memory addresses adjacent to the allocated buffer. Most commonly this occurs when copying strings of characters from one buffer to another.
Basic example
In the following example, a program has defined two data items which are adjacent in memory: an 8-byte-long string buffer, A, and a two-byte integer, B. Initially, A contains nothing but zero bytes, and B contains the number 1979. Characters are one byte wide.
variable name | A | B | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
value | [null string] | 1979 | ||||||||
hex value | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 00 | 07 | BB |
Now, the program attempts to store the null-terminated string
"excessive"
in the A buffer. "excessive"
is 9 characters long, and A can take 8 characters. By failing to check the length of the string, it overwrites the value of B:variable name | A | B | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
value | 'e' | 'x' | 'c' | 'e' | 's' | 's' | 'i' | 'v' | 25856 | |
hex | 65 | 78 | 63 | 65 | 73 | 73 | 69 | 76 | 65 | 00 |
Memory leak
A memory leak, in computer science (or leakage, in this context), occurs when a computer program acquires memory but fails to release it back to the operating system.[1] In object-oriented programming, a memory leak may happen when an object is stored in memory but cannot be accessed by the running code.[2] A memory leak has symptoms similar to a number of other problems (see below) and generally can only be diagnosed by a programmer with access to the program source code.
No comments:
Post a Comment