Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: In "Automated Detection," is "STACK_USE" supposed to be bolded? Also, the van Sprundel 06 reference does not appear in the reference list, but links directly to source. I would fix this and add the reference, but the link appears to be broken or incorrect. Ed.

...

Non-Compliant Code Example

Wiki Markup
C99 \[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] includes support for variable-length arrays (VLAs). If the array length is derived from an untrusted data source, an attacker could cause the process to perform an excessive allocation on the stack.

This non-compliant code example temporarily stores data read from a source file into a buffer. The buffer is allocated on the stack as a variable-length array of size bufsize. If bufsize can be controlled by a malicious user, this code could be exploited to cause a denial-of-service attack.

...

This compliant solution replaces the variable-length array with a call to malloc(). If malloc() fails, the return value can be checked to prevent the program from terminating abnormally.

...