COMMON WEAKNESS ENUMERATIONDraft

CWE-457

Use of Uninitialized Variable

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

Soyutlama

Variant

Yapı

Simple

Sömürü İhtimali

High

Problemi anla

Problem nedir?

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

Genişletilmiş açıklama

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.

Kök neden

Problem nasıl ve ne zaman oluşur?

Yaşam döngüsü evresi

Implementation

In C, using an uninitialized char * in some string libraries will return incorrect results, as the libraries expect the null terminator to always be at the end of a string, even if the string is empty.

Risk

Başarılı sömürü neye yol açar?

Other

Etkilenen güvenlik alanları: Availability, Integrity, 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.
Other

Etkilenen güvenlik alanları: Authorization, 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.

Savunma

Nasıl önlenir ve çözülür?

Implementation

Attack Surface Reduction

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

Build and Compilation

Compilation or Build Hardening

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

Implementation · Operation

Birden fazla yaşam döngüsü evresinde uygulanacak savunma

Detay
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

Detay
Choose a language that is not susceptible to these issues.

Architecture and Design

Mimari ve tasarım yaklaşımı

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

Doğrulama

Nasıl tespit edilir?

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