Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider (sch jbop) (X_X)@==(Q_Q)@

...

If the size of the space requested is zero, the behavior is implementation-defined: either a null NULL pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.

In cases where the memory allocation functions return a non-null NULL pointer, using this pointer results in undefined behavior. Typically the pointer refers to a zero-length block of memory consisting entirely of control structures. Overwriting these control structures will damage the data structures used by the memory manager.

...

However, this commonly recommended idiom has problems with zero-length allocations. If the value of nsize in this example is 0, the standard allows the option of either returning a null NULL pointer or returning a pointer to an invalid (e.g., zero-length) object. In cases where the realloc() function frees the memory but returns a null NULL pointer, execution of the code in this example results in a double free.

...

If this non-compliant code is compiled with gcc 3.4.6 and linked with libc 2.3.4, invoking realloc(p, 0) returns a non-null NULL pointer to a zero-sized object (the same as malloc(0)). However, if the same code is compiled with either Microsoft Visual Studio Version 7.1 or gcc version 4.1.0 , realloc(p, 0) returns a null NULL pointer, resulting in a double-free vulnerability.

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

MEM04-A

3 ( high )

2 ( probable ) 2 (

medium )

P12

L1

Related Vulnerabilities

...