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.)
Use of Inherently Dangerous Function
This vulnerability occurs when code uses functions that are inherently unsafe and cannot be reliably secured, posing a direct risk to application stability and security.
What is CWE-242?
Real-world CVEs caused by CWE-242
-
FTP client uses inherently insecure gets() function and is setuid root on some systems, allowing buffer overflow
Ruta del atacante paso a paso
- 1
The code below calls gets() to read information into a buffer.
- 2
The gets() function in C is inherently unsafe.
- 3
The code below calls the gets() function to read in data from the command line.
- 4
However, gets() is inherently unsafe, because it copies all input from STDIN to the buffer without checking size. This allows the user to provide a string that is larger than the buffer size, resulting in an overflow condition.
Vulnerable C
The code below calls gets() to read information into a buffer.
char buf[BUFSIZE];
gets(buf); Secure pseudo
// Validate, sanitize, or use a safe API before reaching the sink.
function handleRequest(input) {
const safe = validateAndEscape(input);
return executeWithGuards(safe);
} How to prevent CWE-242
- Implementation / Requirements Ban the use of dangerous functions. Use their safe equivalent.
- Testing Use grep or static analysis tools to spot usage of dangerous functions.
How to detect CWE-242
Plexicus detecta automáticamente CWE-242 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.
Frequently asked questions
¿Qué es CWE-242?
This vulnerability occurs when code uses functions that are inherently unsafe and cannot be reliably secured, posing a direct risk to application stability and security.
¿Qué gravedad tiene CWE-242?
MITRE califica la probabilidad de explotación como Alta — esta debilidad se explota activamente en la práctica y debe priorizarse para su remediación.
¿Qué lenguajes o plataformas se ven afectados por CWE-242?
MITRE lists the following affected platforms: C, C++.
¿Cómo puedo prevenir CWE-242?
Ban the use of dangerous functions. Use their safe equivalent. Use grep or static analysis tools to spot usage of dangerous functions.
¿Cómo detecta y corrige Plexicus CWE-242?
El motor SAST de Plexicus detecta la firma de flujo de datos para CWE-242 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-242?
MITRE publica la definición canónica en https://cwe.mitre.org/data/definitions/242.html. También puedes consultar la documentación de OWASP y NIST para guías relacionadas.
Weaknesses related to CWE-242
Use of Prohibited Code
This vulnerability occurs when software incorporates a function, library, or third-party component that has been explicitly banned by the…
Use of Potentially Dangerous Function
This vulnerability occurs when code calls a function that can be dangerous if misused, but can also be used safely with proper…
Further reading
- MITRE — CWE-242 oficial https://cwe.mitre.org/data/definitions/242.html
- Seven Pernicious Kingdoms: A Taxonomy of Software Security Errors https://samate.nist.gov/SSATTM_Content/papers/Seven%20Pernicious%20Kingdoms%20-%20Taxonomy%20of%20Sw%20Security%20Errors%20-%20Tsipenyuk%20-%20Chess%20-%20McGraw.pdf
- Writing Secure Code https://www.microsoftpressstore.com/store/writing-secure-code-9780735617223
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.