Difference between revisions of "Miscalculated null termination"

Jump to: navigation, search
Line 1: Line 1:
[[ASDR Table of Contents]]
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''
Last revision (mm/dd/yy): '''{{REVISIONMONTH}}/{{REVISIONDAY}}/{{REVISIONYEAR}}'''
[[Category:FIXME|This is the text from the old template. This needs to be rewritten using the new template.]]
[[ASDR_TOC_Vulnerabilities|Vulnerabilities Table of Contents]]

Revision as of 19:38, 20 February 2009

This is a Vulnerability. To view all vulnerabilities, please see the Vulnerability Category page.

Last revision (mm/dd/yy): 02/20/2009

Vulnerabilities Table of Contents


Miscalculated null termination occurs when the placement of a null character at the end of a buffer of characters (or string) is misplaced or omitted.


  • Confidentiality: Information disclosure may occur if strings with misplaced or omitted null characters are printed.
  • Availability: A randomly placed null character may put the system into an undefined state, and therefore make it prone to crashing.
  • Integrity: A misplaced null character may corrupt other data in memory
  • Access Control: Should the null character corrupt the process flow, or affect a flag controlling access, it may lead to logical errors which allow for the execution of arbitrary code.

Exposure period

  • Requirements specification: The choice could be made to use a language that is not susceptible to these issues.
  • Implementation: Precise knowledge of string manipulation functions may prevent this issue

Required resources




Likelihood of exploit


Miscalculated null termination is a common issue, and often difficult to detect. The most common symptoms occur infrequently (in the case of problems resulting from "safe" string functions), or in odd ways characterized by data corruption (when caused by off-by-one errors).

The case of an omitted null character is the most dangerous of the possible issues. This will almost certainly result in information disclosure, and possibly a buffer overflow condition, which may be exploited to execute arbitrary code.

As for misplaced null characters, the biggest issue is a subset of buffer overflow, and write-what-where conditions, where data corruption occurs from the writing of a null character over valid data, or even instructions. These logic issues may result in any number of security flaws.

Risk Factors



While the following example is not exploitable, it provides a good example of how nulls can be omitted or misplaced, even when "safe" functions are used:

#include <stdio.h>
#include <string.h>

int main() {   
  char longString[] = "Cellular bananular phone";    
  char shortString[16];    

  strncpy(shortString, longString, 16);    
  printf("The last character in shortString is: %c %1$x\n", 
  return (0);

The above code gives the following output:

The last character in shortString is: l 6c

So, the shortString array does not end in a NULL character, even though the "safe" string function strncpy() was used.

Related Attacks

Related Vulnerabilities

Related Controls

  • Requirements specification: The choice could be made to use a language that is not susceptible to these issues.
  • Implementation: Ensure that all string functions used are understood fully as to how they append null characters. Also, be wary of off-by-one errors when appending nulls to the end of strings.

Related Technical Impacts