| Impact | Details |
|---|---|
|
DoS: Resource Consumption (Memory) |
Scope: Availability
Not controlling memory allocation can result in a request for too much system memory, possibly leading to a crash of the application due to out-of-memory conditions, or the consumption of a large amount of memory on the system.
|
| Phase(s) | Mitigation |
|---|---|
|
Implementation; 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.
|
|
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.
|
| Nature | Type | ID | Name |
|---|---|---|---|
| ChildOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 770 | Allocation of Resources Without Limits or Throttling |
| PeerOf | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 1325 | Improperly Controlled Sequential Memory Allocation |
| CanFollow | Variant Variant - a weakness that is linked to a certain type of product, typically involving a specific language or technology. More specific than a Base weakness. Variant level weaknesses typically describe issues in terms of 3 to 5 of the following dimensions: behavior, property, technology, language, and resource. | 129 | Improper Validation of Array Index |
| CanFollow | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 1284 | Improper Validation of Specified Quantity in Input |
| CanPrecede | Base Base - a weakness that is still mostly independent of a resource or technology, but with sufficient details to provide specific methods for detection and prevention. Base level weaknesses typically describe issues in terms of 2 or 3 of the following dimensions: behavior, property, technology, language, and resource. | 476 | NULL Pointer Dereference |
| Phase | Note |
|---|---|
| Implementation |
C (Undetermined Prevalence)
C++ (Undetermined Prevalence)
Class: Not Language-Specific (Undetermined Prevalence)
Example 1
Consider the following code, which accepts an untrusted size value and allocates a buffer to contain a string of the given size.
Suppose an attacker provides a size value of:
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.
The HashMap constructor will verify that the initial capacity is not negative, however there is no check in place to verify that sufficient memory is present. If the attacker provides a large enough value, the application will run into an OutOfMemoryError.
Example 3
This code performs a stack allocation based on a length calculation.
Since a and b are declared as signed ints, the "a - b" subtraction gives a negative result (-1). However, since len is declared to be unsigned, len is cast to an extremely large positive number (on 32-bit systems - 4294967295). As a result, the buffer buf[len] declaration uses an extremely large size to allocate on the stack, very likely more than the entire computer's memory space.
Miscalculations usually will not be so obvious. The calculation will either be complicated or the result of an attacker's input to attain the negative value.
Example 4
This example shows a typical attempt to parse a string with an error resulting from a difference in assumptions between the caller to a function and the function's action.
The buffer length ends up being -1, resulting in a blown out stack. The space character after the colon is included in the function calculation, but not in the caller's calculation. This, unfortunately, is not usually so obvious but exists in an obtuse series of calculations.
Example 5
The following code obtains an untrusted number that is used as an index into an array of messages.
The index is not validated at all (CWE-129), so it might be possible for an attacker to modify an element in @messages that was not intended. If an index is used that is larger than the current size of the array, the Perl interpreter automatically expands the array so that the large index works.
If $num is a large value such as 2147483648 (1<<31), then the assignment to $messages[$num] would attempt to create a very large array, then eventually produce an error message such as:
Out of memory during array extend
This memory exhaustion will cause the Perl program to exit, possibly a denial of service. In addition, the lack of memory could also prevent many other programs from successfully running on the system.
Example 6
This example shows a typical attempt to parse a string with an error resulting from a difference in assumptions between the caller to a function and the function's action. The buffer length ends up being -1 resulting in a blown out stack. The space character after the colon is included in the function calculation, but not in the caller's calculation. This, unfortunately, is not usually so obvious but exists in an obtuse series of calculations.
Note: this is a curated list of examples for users to understand the variety of ways in which this weakness can be introduced. It is not a complete list of all CVEs that are related to this CWE entry.
| Reference | Description |
|---|---|
|
program uses ::alloca() for encoding messages, but large messages trigger segfault
|
|
|
memory consumption and daemon exit by specifying a large value in a length field
|
|
|
large value in a length field leads to memory consumption and crash when no more memory is available
|
|
|
large key size in game program triggers crash when a resizing function cannot allocate enough memory
|
|
|
large Content-Length HTTP header value triggers application crash in instant messaging application due to failure in memory allocation
|
| Ordinality | Description |
|---|---|
|
Primary
|
(where the weakness exists independent of other weaknesses)
|
Resultant
|
(where the weakness is typically related to the presence of some other weaknesses)
|
| Method | Details |
|---|---|
|
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 |
| Nature | Type | ID | Name |
|---|---|---|---|
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1131 | CISQ Quality Measures (2016) - Security |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1162 | SEI CERT C Coding Standard - Guidelines 08. Memory Management (MEM) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1179 | SEI CERT Perl Coding Standard - Guidelines 01. Input Validation and Data Sanitization (IDS) |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1308 | CISQ Quality Measures - Security |
| MemberOf | CategoryCategory - a CWE entry that contains a set of other entries that share a common characteristic. | 1399 | Comprehensive Categorization: Memory Safety |
Rationale
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.Comments
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.Relationship
Applicable Platform
Uncontrolled memory allocation is possible in many languages, such as dynamic array allocation in perl or initial size parameters in Collections in Java. However, languages like C and C++ where programmers have the power to more directly control memory management will be more susceptible.
| Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
|---|---|---|---|
| WASC | 35 | SOAP Array Abuse | |
| CERT C Secure Coding | MEM35-C | Imprecise | Allocate sufficient memory for an object |
| SEI CERT Perl Coding Standard | IDS32-PL | Imprecise | Validate any integer that is used as an array index |
| OMG ASCSM | ASCSM-CWE-789 |
| Submissions | |||
|---|---|---|---|
| Submission Date | Submitter | Organization | |
|
2009年10月21日
(CWE 1.6, 2009年10月29日) |
CWE Content Team | MITRE | |
| Modifications | |||
| Modification Date | Modifier | Organization | |
|
2025年09月09日
(CWE 4.18, 2025年09月09日) |
CWE Content Team | MITRE | |
| updated Affected_Resources, Functional_Areas, Observed_Examples | |||
| 2023年06月29日 | CWE Content Team | MITRE | |
| updated Mapping_Notes, Relationships | |||
| 2023年04月27日 | CWE Content Team | MITRE | |
| updated Detection_Factors, Relationships | |||
| 2022年10月13日 | CWE Content Team | MITRE | |
| updated Observed_Examples | |||
| 2021年03月15日 | CWE Content Team | MITRE | |
| updated Demonstrative_Examples, Relationships | |||
| 2020年12月10日 | CWE Content Team | MITRE | |
| updated Alternate_Terms, Demonstrative_Examples, Description, Likelihood_of_Exploit, Name, Observed_Examples, Relationships, Time_of_Introduction | |||
| 2020年08月20日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年06月25日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2020年02月24日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2019年06月20日 | CWE Content Team | MITRE | |
| updated Relationships | |||
| 2019年01月03日 | CWE Content Team | MITRE | |
| updated References, Relationships, Taxonomy_Mappings | |||
| 2017年11月08日 | CWE Content Team | MITRE | |
| updated Applicable_Platforms, Taxonomy_Mappings | |||
| 2012年05月11日 | CWE Content Team | MITRE | |
| updated References | |||
| 2011年06月01日 | CWE Content Team | MITRE | |
| updated Common_Consequences | |||
| 2011年03月29日 | CWE Content Team | MITRE | |
| updated Common_Consequences, Observed_Examples | |||
| 2010年02月16日 | CWE Content Team | MITRE | |
| updated Taxonomy_Mappings | |||
| Previous Entry Names | |||
| Change Date | Previous Entry Name | ||
| 2020年12月10日 | Uncontrolled Memory Allocation | ||
Use of the Common Weakness Enumeration (CWE™) and the associated references from this website are subject to the Terms of Use. CWE is sponsored by the U.S. Department of Homeland Security (DHS) Cybersecurity and Infrastructure Security Agency (CISA) and managed by the Homeland Security Systems Engineering and Development Institute (HSSEDI) which is operated by The MITRE Corporation (MITRE). Copyright © 2006–2025, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation.