Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

On many platforms dereferencing a null pointer results in abnormal program termination, but this is not required by the standard. See See "Clever Attack Exploits Fully-Patched Linux Kernel" [Goodin 2009] for an example of a code execution exploit that resulted from a null pointer dereference.

...

If length has the value −1, the addition wraps around to 0, and png_malloc() subsequently returns a null pointer, which is assigned to chunkdata. The chunkdata pointer is later used as a destination argument in a call to memcpy(), resulting in user-defined data overwriting memory starting at address 0. In the case of the ARM and XScale architectures, the 0x0 address is mapped in memory and serves as the exception vector table; consequently, dereferencing 0x0 did not cause program termination.

...

This compliant solution ensures that the pointer returned by png_malloc() is not null.  It It also uses the unsigned type size_t to pass the length parameter, ensuring that negative values are not passed to func().

...

In this noncompliant code example, input_str is copied into dynamically allocated memory referenced by str. If malloc() fails, it returns a null pointer that is assigned to str. When str is dereferenced in memcpy(), the program exhibits undefined behavior.  Additionally, if input_str is a null pointer, the call to strlen() dereferences a null pointer, resulting in undefined behavior. This code also violates MEM32-C. Detect and handle memory allocation errors.

...

Dereferencing a null pointer results in undefined behavior, typically abnormal program termination. In some situations, however, dereferencing a null pointer can lead to the execution of arbitrary code [Jack 2007, van Sprundel 2006]. The indicated severity is for this more severe case; on platforms where it is not possible to exploit a null pointer dereference to execute arbitrary code, the actual severity is low.

...

ToolVersionCheckerDescription
Compass/ROSE  

Can detect violations of this rule. In particular, ROSE ensures that any pointer returned by malloc(), calloc(), or realloc() is first checked for NULL before being used (otherwise, it is free()-ed). ROSE does not handle cases where an allocation is assigned to an lvalue that is not a variable (such as a struct member or C++ function call returning a reference)

Coverity

 

Include Page
Coverity_V
Coverity_V

CHECKED_RETURN

NULL_RETURNS

REVERSE_INULL

FORWARD_NULL

Finds instances where a pointer is checked against NULL and then later dereferenced

Identifies functions that can return a null pointer but are not checked

Identifies code that dereferences a pointer and then checks the pointer against NULL

Can find the instances where NULL is explicitly dereferenced or a pointer is checked against NULL but then dereferenced anyway. Coverity Prevent cannot discover all violations of this rule, so further verification is necessary

Fortify SCA

5.0

 

  

Klocwork

 
Include Page
Klocwork_V
Klocwork_V
 

NPD.* *RNPD.*

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

45 D

Fully implemented
PRQA QA-C
Include Page
PRQA_V
PRQA_V

0504  
0505  
0506  

Fully implemented

Splint

Include Page
Splint_V
Splint_V
  

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...