CWE-242

Base Abstraction Level
Pillar — Highest-level weakness category
Class — Abstract, language-independent
Base — Specific enough to detect
Variant — Tied to specific technology
Compound — Requires multiple weaknesses
Draft MITRE CWE Status
Stable — Fully reviewed and complete
Draft — Under development, may change
Incomplete — Partially defined by MITRE
Deprecated — No longer recommended
Obsolete — Replaced by another CWE
Exploit: High
Use of Inherently Dangerous Function

Description

The product calls a function that can never be guaranteed to work safely, regardless of how it is used.

Consequences

Other — Varies by Context

The consequences vary depending on the behavior of the affected function.

Other — Modify Memory

Some functions can be subject to buffer overflows. For example, an attacker can easily send arbitrarily-sized input to gets() and overflow the destination buffer. In C++, an attacker can easily send arbitrarily-sized input to the >> operator and overflow the destination buffer.

Mitigations

Phase: Build and Compilation, Implementation

Identify a list of prohibited API functions and prohibit developers from using these functions, providing safer alternatives. In some cases, automatic code analysis tools or the compiler can be instructed to spot use of prohibited functions, such as the "banned.h" include file from Microsoft's SDL. [REF-554] [REF-1009] [REF-7]

Phase: Testing

Use grep or static analysis tools to spot usage of dangerous functions.

Detection

Automated Static Analysis

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