[Forgot Password]
Login  Register Subscribe

30430

 
 

423868

 
 

247974

 
 

909

 
 

194654

 
 

282

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

Release of Invalid Pointer or Reference

ID: 763Date: (C)2012-05-14   (M)2022-10-10
Type: weaknessStatus: INCOMPLETE
Abstraction Type: Base





Description

The application attempts to return a memory resource to the system, but calls the wrong release function or calls the appropriate release function incorrectly.

Extended Description

This weakness can take several forms, such as:

The memory was allocated, explicitly or implicitly, via one memory management method and deallocated using a different, non-compatible function (CWE-762).

The function calls or memory management routines chosen are appropriate, however they are used incorrectly, such as in CWE-761.

Applicable Platforms
None

Time Of Introduction

  • Implementation

Common Consequences

ScopeTechnical ImpactNotes
Integrity
Availability
Confidentiality
 
Modify memory
DoS: crash / exit / restart
Execute unauthorized code or commands
 
This weakness may result in the corruption of memory, and perhaps instructions, possibly leading to a crash. If the corrupted memory can be effectively controlled, it may be possible to execute arbitrary code.
 

Detection Methods
None

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
Implementation
 
 Only call matching memory management functions. Do not mix and match routines. For example, when you allocate a buffer with malloc(), dispose of the original pointer with free().
 
  
Implementation
 
 When programming in C++, consider using smart pointers provided by the boost library to help correctly and consistently manage memory.
 
  
Architecture and Design
Implementation
Operation
 
Libraries or Frameworks
 
Use a vetted library or framework that does not allow this weakness to occur or provides constructs that make this weakness easier to avoid.
For example, glibc in Linux provides protection against free of invalid pointers.
 
  
Architecture and Design
 
 Use a language that provides abstractions for memory allocation and deallocation.
 
  
Testing
 
 Use a tool that dynamically detects memory management problems, such as valgrind.
 
  

Relationships

Related CWETypeViewChain
CWE-763 ChildOf CWE-891 Category CWE-888  

Demonstrative Examples   (Details)

  1. Consider the following code in the context of a parsing application to extract commands out of user data. The intent is to parse each command and add it to a queue of commands to be executed, discarding each malformed entry. (Demonstrative Example Id DX-79)
  2. In this example, the programmer dynamically allocates a buffer to hold a string and then searches for a specific character. After completing the search, the programmer attempts to release the allocated memory and return SUCCESS or FAILURE to the caller. Note: for simplification, this example uses a hard-coded "Search Me!" string and a constant string length of 20. (Demonstrative Example Id DX-77)
  3. This code attempts to tokenize a string and place it into an array using the strsep function, which inserts a \0 byte in place of whitespace or a tab character. After finishing the loop, each string in the AP array points to a location within the input string. (Demonstrative Example Id DX-78)
  4. This example allocates a BarObj object using the new operator in C++, however, the programmer then deallocates the object using free(), which may lead to unexpected behavior. (Demonstrative Example Id DX-80)

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings
None

References:

  1. .boost C++ Library Smart Pointers.
  2. .Valgrind.
CVE    30
CVE-2013-4695
CVE-2021-22760
CVE-2021-21401
CVE-2021-24028
...

© SecPod Technologies