CWE-825 Base Incomplet

Expired Pointer Dereference

This vulnerability occurs when a program tries to use a pointer that still points to a memory location that has already been freed or released.

Définition

What is CWE-825?

This vulnerability occurs when a program tries to use a pointer that still points to a memory location that has already been freed or released.
This issue, often called a 'use-after-free' scenario, happens when your code frees a block of memory but accidentally keeps a reference (pointer) to it. Later, when that same pointer is used to read or write data, the memory may have been reallocated for a completely different purpose within your application or system. This means you're now interacting with data you didn't intend to, leading to unpredictable behavior. The consequences depend entirely on what now occupies that memory region. You might crash the program (denial of service), read sensitive information that belongs elsewhere (information exposure), or, in the worst case, have attacker-controlled data executed as code. This makes expired pointer dereference a critical weakness that can serve as a gateway to severe security breaches.
Impact réel

Real-world CVEs caused by CWE-825

  • access of expired memory address leads to arbitrary code execution

  • stale pointer issue leads to denial of service and possibly other consequences

  • Chain: a message having an unknown message type may cause a reference to uninitialized memory resulting in a null pointer dereference (CWE-476) or dangling pointer (CWE-825), possibly crashing the system or causing heap corruption.

  • read of value at an offset into a structure after the offset is no longer valid

Comment les attaquants l'exploitent

Parcours de l'attaquant étape par étape

  1. 1

    The following code shows a simple example of a use after free error:

  2. 2

    When an error occurs, the pointer is immediately freed. However, this pointer is later incorrectly used in the logError function.

  3. 3

    The following code shows a simple example of a double free error:

  4. 4

    Double free vulnerabilities have two common (and sometimes overlapping) causes:

  5. 5

    - Error conditions and other exceptional circumstances - Confusion over which part of the program is responsible for freeing the memory

Exemple de code vulnérable

Vulnerable C

The following code shows a simple example of a use after free error:

Vulnérable C
char* ptr = (char*)malloc (SIZE);
  if (err) {
  	abrt = 1;
  	free(ptr);
  }
  ...
  if (abrt) {
  	logError("operation aborted before commit", ptr);
  }
Exemple de code sécurisé

Secure pseudo

Sécurisé pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
  const safe = validateAndEscape(input);
  return executeWithGuards(safe);
}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Liste de contrôle de prévention

How to prevent CWE-825

  • Architecture and Design Choose a language that provides automatic memory management.
  • Implementation When freeing pointers, be sure to set them to NULL once they are freed. However, the utilization of multiple or complex data structures may lower the usefulness of this strategy.
Signaux de détection

How to detect CWE-825

SAST High

Exécuter une analyse statique (SAST) sur le code source à la recherche du motif non sécurisé dans le flux de données.

DAST Moderate

Exécuter des tests de sécurité applicative dynamique (DAST) contre le point de terminaison en ligne.

Runtime Moderate

Surveiller les journaux runtime pour détecter des traces d'exception inhabituelles, des entrées malformées ou des tentatives de contournement d'autorisation.

Code review Moderate

Revue de code : signaler tout nouveau code qui traite les entrées de cette surface sans utiliser les helpers du framework validés.

Correction automatique Plexicus

Plexicus détecte automatiquement CWE-825 et ouvre une PR de correction en moins de 60 secondes.

Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.

Questions fréquentes

Frequently asked questions

Qu'est-ce que CWE-825 ?

This vulnerability occurs when a program tries to use a pointer that still points to a memory location that has already been freed or released.

Quelle est la gravité de CWE-825 ?

MITRE n'a pas publié de note de probabilité d'exploitation pour cette faiblesse. Traitez-la comme un impact moyen jusqu'à ce que votre modèle de menace prouve le contraire.

Quels langages ou plateformes sont affectés par CWE-825 ?

MITRE lists the following affected platforms: C, C++.

Comment puis-je prévenir CWE-825 ?

Choose a language that provides automatic memory management. When freeing pointers, be sure to set them to NULL once they are freed. However, the utilization of multiple or complex data structures may lower the usefulness of this strategy.

Comment Plexicus détecte et corrige CWE-825 ?

Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-825 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.

Où puis-je en savoir plus sur CWE-825 ?

MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/825.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.

Faiblesses associées

Weaknesses related to CWE-825

CWE-119 Parent

Improper Restriction of Operations within the Bounds of a Memory Buffer

This vulnerability occurs when software accesses a memory buffer but reads from or writes to a location outside its allocated boundary.…

CWE-120 Frère

Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')

This vulnerability occurs when a program copies data from one memory location to another without first verifying that the source data will…

CWE-123 Frère

Write-what-where Condition

A write-what-where condition occurs when an attacker can control both the data written and the exact memory location where it's written,…

CWE-125 Frère

Out-of-bounds Read

An out-of-bounds read occurs when software accesses memory outside the boundaries of a buffer, array, or similar data structure, reading…

CWE-130 Frère

Improper Handling of Length Parameter Inconsistency

This vulnerability occurs when a program reads a structured data packet or message but fails to properly validate that the declared length…

CWE-466 Frère

Return of Pointer Value Outside of Expected Range

This vulnerability occurs when a function returns a memory pointer that points outside the expected buffer range, potentially exposing…

CWE-786 Frère

Access of Memory Location Before Start of Buffer

This vulnerability occurs when software attempts to read from or write to a memory location positioned before the official start of a…

CWE-787 Frère

Out-of-bounds Write

This vulnerability occurs when software incorrectly writes data outside the boundaries of its allocated memory buffer, either beyond the…

CWE-788 Frère

Access of Memory Location After End of Buffer

This vulnerability occurs when software attempts to read from or write to a memory buffer using an index or pointer that points past the…

Prêt quand vous l'êtes

Arrêtez de payer par développeur.
Commencez à fermer la boucle.

Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.