CWE-590 Variante Incompleto

Free of Memory not on the Heap

This vulnerability occurs when a program calls free() on a memory pointer that wasn't originally allocated using standard heap functions like malloc(), calloc(), or realloc().

Definición

What is CWE-590?

This vulnerability occurs when a program calls free() on a memory pointer that wasn't originally allocated using standard heap functions like malloc(), calloc(), or realloc().
Calling free() on an invalid pointer corrupts the program's internal memory management structures. This corruption typically leads to a crash, but it can also create opportunities for an attacker to manipulate the memory process. In some cases, an attacker can steer the free() operation to target controllable memory locations, potentially altering critical variables or even executing malicious code. Detecting these 'invalid free' issues manually is challenging, as they often involve complex pointer tracking across codebases. While SAST tools can flag the pattern, Plexicus uses AI to analyze the data flow and suggest precise code fixes, transforming a tedious security hunt into an automated remediation step and saving significant developer time.
Impacto en el mundo real

Real-world CVEs caused by CWE-590

Todavía no hay CVEs públicos enlazados a esta CWE en el catálogo de MITRE.

Cómo lo explotan los atacantes

Ruta del atacante paso a paso

  1. 1

    In this example, an array of record_t structs, bar, is allocated automatically on the stack as a local variable and the programmer attempts to call free() on the array. The consequences will vary based on the implementation of free(), but it will not succeed in deallocating the memory.

  2. 2

    This example shows the array allocated globally, as part of the data segment of memory and the programmer attempts to call free() on the array.

  3. 3

    Instead, if the programmer wanted to dynamically manage the memory, malloc() or calloc() should have been used.

  4. 4

    Additionally, global variables could be passed to free() when they are pointers to dynamically allocated memory.

Ejemplo de código vulnerable

Vulnerable C

In this example, an array of record_t structs, bar, is allocated automatically on the stack as a local variable and the programmer attempts to call free() on the array. The consequences will vary based on the implementation of free(), but it will not succeed in deallocating the memory.

Vulnerable C
void foo(){
  		record_t bar[MAX_SIZE];
```
/* do something interesting with bar */* 
  		
  		...
  		free(bar);}
Ejemplo de código seguro

Secure C

Instead, if the programmer wanted to dynamically manage the memory, malloc() or calloc() should have been used.

Seguro C
void foo(){
  		record_t *bar = (record_t*)malloc(MAX_SIZE*sizeof(record_t));
```
/* do something interesting with bar */* 
  		
  		...
  		free(bar);}
What changed: the unsafe sink is replaced (or the input is validated/escaped) so the same payload no longer triggers the weakness.
Lista de prevención

How to prevent CWE-590

  • Implementation Only free pointers that you have called malloc on previously. This is the recommended solution. Keep track of which pointers point at the beginning of valid chunks and free them only once.
  • Implementation Before freeing a pointer, the programmer should make sure that the pointer was previously allocated on the heap and that the memory belongs to the programmer. Freeing an unallocated pointer will cause undefined behavior in the program.
  • Architecture and Design 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.
Señales de detección

How to detect CWE-590

Fuzzing High

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.

Automated Static Analysis High

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.)

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-590 y abre un PR de corrección en menos de 60 segundos.

Codex Remedium escanea cada commit, identifica esta debilidad concreta y entrega un pull request listo para revisión con el parche. Sin tickets. Sin traspasos.

Preguntas frecuentes

Frequently asked questions

¿Qué es CWE-590?

This vulnerability occurs when a program calls free() on a memory pointer that wasn't originally allocated using standard heap functions like malloc(), calloc(), or realloc().

¿Qué gravedad tiene CWE-590?

MITRE no ha publicado una calificación de probabilidad de explotación para esta debilidad. Trátala como de impacto medio hasta que tu modelo de amenazas demuestre lo contrario.

¿Qué lenguajes o plataformas se ven afectados por CWE-590?

MITRE no ha especificado plataformas afectadas para esta CWE — puede aplicar a la mayoría de los stacks de aplicaciones.

¿Cómo puedo prevenir CWE-590?

Only free pointers that you have called malloc on previously. This is the recommended solution. Keep track of which pointers point at the beginning of valid chunks and free them only once. Before freeing a pointer, the programmer should make sure that the pointer was previously allocated on the heap and that the memory belongs to the programmer. Freeing an unallocated pointer will cause undefined behavior in the program.

¿Cómo detecta y corrige Plexicus CWE-590?

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-590 en cada commit. Cuando hay coincidencia, nuestro agente Codex Remedium abre un PR de corrección con el código corregido, las pruebas y un resumen de una línea para el revisor.

¿Dónde puedo aprender más sobre CWE-590?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/590.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.

Listo cuando tú lo estés

Deja de pagar por desarrollador.
Empieza a cerrar el bucle.

Plexicus es el ASPM nativo de IA que escanea, filtra, corrige, pentestea y explica — de forma autónoma. Desarrolladores ilimitados, repos ilimitados, acciones de IA de uso justo. Nivel gratuito real, €269/mo anual cuando estés listo.