1675
Detection Methods
Fuzzing
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs
- either randomly or algorithmically - and dynamically invoking the code with those inputs.
Even with random inputs, it is often capable of generating unexpected results such as crashes,
memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases
that clearly indicate bugs, which helps developers to diagnose the issues.
Effectiveness = High
Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST),
can find some instances of this weakness by analyzing source code (or binary/compiled code)
without having to execute it. Typically, this is done by building a model of data flow and control
flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input)
with "sinks" (destinations where the data interacts with external components, a lower layer such
as the OS, etc.)
Effectiveness = High
Potential Mitigations
Phase: Implementation
Phase: Architecture and Design
Perform adequate input validation against any value that influences the amount of memory
that is allocated. Define an appropriate strategy for handling requests that exceed the limit, and
consider supporting a configuration option so that the administrator can extend the amount of
memory to be used if necessary.
Phase: Operation
Run your program using system-provided resource limits for memory. This might still cause the
program to crash or exit, but the impact to the rest of the system will be minimized.
Demonstrative Examples
Example 1:
Consider the following code, which accepts an untrusted size value and allocates a buffer to
contain a string of the given size.
Example Language: C (Bad)
unsigned int size = GetUntrustedInt();
/* ignore integer overflow (CWE-190) for this example */
unsigned int totBytes = size * sizeof(char);
char *string = (char *)malloc(totBytes);
InitializeString(string);
Suppose an attacker provides a size value of:
12345678
This will cause 305,419,896 bytes (over 291 megabytes) to be allocated for the string.
Example 2:
Consider the following code, which accepts an untrusted size value and uses the size as an initial
capacity for a HashMap.
Example Language: Java (Bad)
unsigned int size = GetUntrustedInt();
CWE Version 4.14
CWE-789: Memory Allocation with Excessive Size Value
CWE-789: Memory Allocation with Excessive Size Value