---
title: "CWE-457: Use of Uninitialized Variable"
url: https://radicalnotion.ai/cwe/cwe-457
type: cwe
description: "The code uses a variable that has not been initialized, leading to unpredictable or unintended results."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-457: Use of Uninitialized Variable

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 314
- **Of those, in CISA KEV:** 0
- **New in 2026:** 200
- **CWE catalog version:** 4.21

## Description

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

## Background

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

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | The presence of an uninitialized variable can sometimes indicate a typographic error in the code. |
| 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. |

## Applicable platforms

**Languages:** C (Sometimes), C++ (Sometimes), Perl (Often), PHP (Often)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality, Integrity, Availability, Other | Varies by Context, Read Application Data | Uninitialized variables usually contain junk, which can not be trusted for consistency. Depending on the context, uninitialized variables could lead to denial of service conditions, or modify control flow in unexpected ways. They could also contain sensitive information that could be leaked if the variable is used in output. In some cases, an attacker can "pre-initialize" the variable using previous actions - i.e., control the contents of the variable - which might enable code execution. |
| Availability | Alter Execution Logic, Unexpected State | This can cause a race condition if a lock variable check passes when it should not. |
| Authorization, Other | Varies by Context | 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. |

## Potential mitigations

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

## Detection methods

### Fuzzing

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.

Effectiveness: High

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

Effectiveness: High

## Demonstrative examples

### Example 1

This code prints a greeting using information stored in a POST request:

Bad code:

```php
if (isset($_POST['names'])) {
    $nameArray = $_POST['names'];
}
echo "Hello " . $nameArray['first'];
```

This code checks if the POST array 'names' is set before assigning it to the $nameArray variable. However, if the array is not in the POST request, $nameArray will remain uninitialized. This will cause an error when the array is accessed to print the greeting message, which could lead to further exploit.

### Example 2

The following switch statement is intended to set the values of the variables aN and bN before they are used:

Bad code:

```c
int aN, Bn;
switch (ctl) {
    case -1:
        aN = 0;
        bN = 0;
        break;

    case 0:
        aN = i;
        bN = -i;
        break;

    case 1:
        aN = i + NEXT_SZ;
        bN = i - NEXT_SZ;
        break;

    default:
        aN = -1;
        aN = -1;
        break;
}
repaint(aN, bN);
```

In the default case of the switch statement, the programmer has accidentally set the value of aN twice. As a result, bN will have an undefined value. Most uninitialized variable issues result in general software reliability problems, but if attackers can intentionally trigger the use of an uninitialized variable, they might be able to launch a denial of service attack by crashing the program. Under the right circumstances, an attacker may be able to control the value of an uninitialized variable by affecting the values on the stack prior to the invocation of the function.

### Example 3

This example will leave test\_string in an unknown condition when i is the same value as err\_val, because test\_string is not initialized (CWE-456). Depending on where this code segment appears (e.g. within a function body), test\_string might be random if it is stored on the heap or stack. If the variable is declared in static memory, it might be zero or NULL. Compiler optimization might contribute to the unpredictability of this address.

Bad code:

```c
char *test_string;
if (i != err_val)
{
    test_string = "Hello World!";
}
printf("%s", test_string);
```

Good code:

```c
char *test_string = "Done at the beginning";
if (i != err_val)
{
    test_string = "Hello World!";
}
printf("%s", test_string);
```

Good code:

```c
char *test_string;
if (i != err_val)
{
    test_string = "Hello World!";
}
else {
    test_string = "Done on the other side!";
}
printf("%s", test_string);
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2019-15900 | Chain: sscanf() call is used to check if a username and group exists, but the return value of sscanf() call is not checked (CWE-252), causing an uninitialized variable to be checked (CWE-457), returning success to allow authorization bypass for executing a privileged (CWE-863). |
| CVE-2008-3688 | Chain: A denial of service may be caused by an uninitialized variable (CWE-457) allowing an infinite loop (CWE-835) resulting from a connection to an unresponsive server. |
| CVE-2008-0081 | Uninitialized variable leads to code execution in popular desktop application. |
| CVE-2007-4682 | Crafted input triggers dereference of an uninitialized object pointer. |
| CVE-2007-3468 | Crafted audio file triggers crash when an uninitialized variable is used. |
| CVE-2007-2728 | Uninitialized random seed variable used. |

## Real CVEs with this weakness (sample of 12 of 314)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-90104 | NFSv4.1: zero referring call lists before decoding | critical | 9.8 | - | No | 2026-09-17 |
| CVE-2026-74315 | lockd: Avoid hashing uninitialized bytes in nlm4svc\_lookup\_file() | critical | 9.8 | - | No | 2026-08-15 |
| CVE-2026-72020 | ipvs: reset full ip\_vs\_seq structs in ip\_vs\_conn\_new | critical | 9.8 | - | No | 2026-08-15 |
| CVE-2026-53374 | drm/amdgpu: zero-initialize GART table on allocation | critical | 9.8 | - | No | 2026-07-19 |
| CVE-2026-52931 | batman-adv: tp\_meter: avoid use of uninit sender vars | critical | 9.8 | - | No | 2026-06-24 |
| CVE-2026-6748 | Uninitialized memory in the Audio/Video: Web Codecs component | critical | 9.8 | - | No | 2026-04-21 |
| CVE-2024-32611 | - | critical | 9.8 | - | No | 2024-05-09 |
| CVE-2022-40510 | Buffer copy without checking size of input in Audio. | critical | 9.8 | - | No | 2023-08-08 |
| CVE-2022-21217 | Reolink RLC-410W device TestEmail out-of-bounds write vulnerability | critical | 9.8 | - | No | 2022-01-28 |
| CVE-2021-40418 | Blackmagic Design DaVinci Resolve R3D DPDecoder Service frame parsing uninitialized uuid object vulnerability | critical | 9.8 | - | No | 2021-12-22 |
| CVE-2026-78935 | Use of uninitialized variable in Mobile | critical | 9.6 | - | No | 2026-08-25 |
| CVE-2026-14405 | Uninitialized Use in V8 | critical | 9.6 | - | No | 2026-07-01 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-665](https://radicalnotion.ai/cwe/cwe-665) | Improper Initialization |
| Parent | [CWE-908](https://radicalnotion.ai/cwe/cwe-908) | Use of Uninitialized Resource |
| Related | [CWE-456](https://radicalnotion.ai/cwe/cwe-456) | Missing Initialization of a Variable |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Uninitialized variable | - | - |
| 7 Pernicious Kingdoms | Uninitialized Variable | - | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |
| SEI CERT Perl Coding Standard | Declare identifiers before using them | DCL33-PL | Imprecise |

## Frequently asked questions

### What is CWE-457?

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

### What CVEs are caused by CWE-457?

314 recorded CVEs are attributed to CWE-457, including CVE-2026-90104, CVE-2026-74315 and CVE-2026-72020.

### How do you prevent CWE-457?

Ensure that critical variables are initialized before first use.

### How is CWE-457 detected?

Fuzzing: 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.

### What are the consequences of CWE-457?

Exploiting CWE-457 can lead to: Varies by Context, Read Application Data, Alter Execution Logic, Unexpected State.

### Is CWE-457 actively exploited?

314 recorded CVEs are caused by CWE-457; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/457.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-457). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
