[Forgot Password]
Login  Register Subscribe

30479

 
 

423868

 
 

251139

 
 

909

 
 

196159

 
 

282

Paid content will be excluded from the download.


Download | Alert*
CWE
view XML

Free of Pointer not at Start of Buffer

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





Description

The application calls free() on a pointer to a memory resource that was allocated on the heap, but the pointer is not at the start of the buffer.

Extended Description

This can cause the application to crash, or in some cases, modify critical program variables or execute code.

This weakness often occurs when the memory is allocated explicitly on the heap with one of the malloc() family functions and free() is called, but pointer arithmetic has caused the pointer to be in the interior or end of the buffer.

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
 
 

Detection Methods
None

Potential Mitigations

PhaseStrategyDescriptionEffectivenessNotes
Implementation
 
 When utilizing pointer arithmetic to traverse a buffer, use a separate variable to track progress through memory and preserve the originally allocated address for later freeing.
 
  
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-761 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)

White Box Definitions
None

Black Box Definitions
None

Taxynomy Mappings
None

References:

  1. .boost C++ Library Smart Pointers.
  2. .Valgrind.

© SecPod Technologies