CWE-762 Variante Incompleto Low likelihood

Mismatched Memory Management Routines

This vulnerability occurs when a program uses incompatible functions to allocate and free memory. For example, freeing memory with a function that doesn't match the one used to create it, like…

Definición

What is CWE-762?

This vulnerability occurs when a program uses incompatible functions to allocate and free memory. For example, freeing memory with a function that doesn't match the one used to create it, like mixing different memory management systems.
Mismatched memory management happens when allocation and deallocation routines come from incompatible sources. Common examples include trying to free stack-allocated memory with `free()` (which only works for heap memory), or allocating with C's `malloc()` but deallocating with C++'s `delete` operator. These functions manage memory in fundamentally different ways, and swapping them breaks the underlying memory manager's expectations. The consequences range from immediate crashes and data corruption to more severe security issues like memory corruption exploits that could lead to arbitrary code execution. The severity depends on the specific routines involved, the program's memory layout, and whether an attacker can control or influence the mismatched operation.
Impacto en el mundo real

Real-world CVEs caused by CWE-762

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

    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.

  2. 2

    Instead, the programmer should have either created the object with one of the malloc family functions, or else deleted the object with the delete operator.

  3. 3

    In this example, the program does not use matching functions such as malloc/free, new/delete, and new[]/delete[] to allocate/deallocate the resource.

  4. 4

    In this example, the program calls the delete[] function on non-heap memory.

Ejemplo de código vulnerable

Vulnerable C++

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.

Vulnerable C++
void foo(){
  		BarObj *ptr = new BarObj()
```
/* do some work with ptr here */* 
  		
  		...
  		
  		free(ptr);}
Ejemplo de código seguro

Secure C++

Instead, the programmer should have either created the object with one of the malloc family functions, or else deleted the object with the delete operator.

Seguro C++
void foo(){
  		BarObj *ptr = new BarObj()
```
/* do some work with ptr here */* 
  		
  		...
  		
  		delete ptr;}
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-762

  • 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 Choose a language or tool that provides automatic memory management, or makes manual memory management less error-prone. For example, glibc in Linux provides protection against free of invalid pointers. When using Xcode to target OS X or iOS, enable automatic reference counting (ARC) [REF-391]. To help correctly and consistently manage memory when programming in C++, consider using a smart pointer class such as std::auto_ptr (defined by ISO/IEC ISO/IEC 14882:2003), std::shared_ptr and std::unique_ptr (specified by an upcoming revision of the C++ standard, informally referred to as C++ 1x), or equivalent solutions such as Boost.
  • 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-762

SAST High

Ejecuta análisis estático (SAST) sobre el código buscando el patrón inseguro en el flujo de datos.

DAST Moderate

Ejecuta pruebas dinámicas de seguridad de aplicaciones (DAST) contra el endpoint en vivo.

Runtime Moderate

Vigila los logs en tiempo de ejecución para detectar trazas de excepción inusuales, entradas malformadas o intentos de bypass de autorización.

Code review Moderate

Revisión de código: marca cualquier código nuevo que maneje entrada desde esta superficie sin usar los helpers validados del framework.

Auto-corrección de Plexicus

Plexicus detecta automáticamente CWE-762 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-762?

This vulnerability occurs when a program uses incompatible functions to allocate and free memory. For example, freeing memory with a function that doesn't match the one used to create it, like mixing different memory management systems.

¿Qué gravedad tiene CWE-762?

MITRE califica la probabilidad de explotación como Baja — la explotación es poco frecuente, pero la debilidad debe corregirse cuando se descubra.

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

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

¿Cómo puedo prevenir CWE-762?

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(). Choose a language or tool that provides automatic memory management, or makes manual memory management less error-prone. For example, glibc in Linux provides protection against free of invalid pointers. When using Xcode to target OS X or iOS, enable automatic reference counting (ARC) [REF-391]. To help correctly and…

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

El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-762 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-762?

MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/762.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.