Katalog CWE

CWE-457 · Słabość

Use of Uninitialized Variable

Abstrakcja
Wariant
Status
Szkic
Ryzyko wykorzystania
wysokie
Dodano
19 lipca 2006
Ostatnia zmiana
11 grudnia 2025

Podatności CVE z tą słabościąPełny wpis na cwe.mitre.org ↗

Opis

The code uses a variable that has not been initialized, leading to unpredictable or unintended results.

In some languages such as C and C++, stack variables are not initialized by default. They generally contain junk data with the contents of stack memory before the function was invoked. An attacker can sometimes control or read these contents. In other languages or conditions, a variable that is not explicitly initialized can be given a default value that has security implications, depending on the logic of the program. The presence of an uninitialized variable can sometimes indicate a typographic error in the code.

Skutki

  • Availability, Integrity, Other

    Other

    Initial variables usually contain junk, which can not be trusted for consistency. This can lead to denial of service conditions, or modify control flow in unexpected ways. In some cases, an attacker can "pre-initialize" the variable using previous actions, which might enable code execution. This can cause a race condition if a lock variable check passes when it should not.

  • Authorization, Other

    Other

    Strings that are not initialized are especially dangerous, since many functions expect a null at the end -- and only at the end -- of a string.

Zapobieganie

  • Implementation · Attack Surface Reduction

    Ensure that critical variables are initialized before first use [REF-1485].

  • Build and Compilation · Compilation or Build Hardening

    Most compilers will complain about the use of uninitialized variables if warnings are turned on.

  • Implementation, Operation

    When using a language that does not require explicit declaration of variables, run or compile the software in a mode that reports undeclared or unknown variables. This may indicate the presence of a typographic error in the variable's name.

  • Requirements · Language Selection

    Choose a language that is not susceptible to these issues.

  • Architecture and Design

    Mitigating technologies such as safe string libraries and container abstractions could be introduced.

Przykłady podatności

Słabość nadrzędna

Kiedy powstaje

Dotyczy

C, C++, Perl, PHP, Not Language-Specific

Źródła

  1. The CLASP Application Security Process — Secure Software, Inc., 2005
  2. Exploiting Uninitialized Data — mercy, 2006
  3. MS08-014 : The Case of the Uninitialized Stack Variable Vulnerability — Microsoft Security Vulnerability Research & Defense, 2008
  4. 24 Deadly Sins of Software Security — Michael Howard, David LeBlanc, John Viega, "Sin 8: C++ Catastrophes." Page 143, McGraw-Hill, 2010
  5. The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 7, "Variable Initialization", Page 312, Addison Wesley, 2006
  6. D3FEND: D3-VI Variable Initialization — D3FEND

Wpis z katalogu CWE 4.20.