---
title: "CWE-456: Missing Initialization of a Variable"
url: https://radicalnotion.ai/cwe/cwe-456
type: cwe
description: "The product does not initialize critical variables."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-456: Missing Initialization of a Variable

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 14
- **Of those, in CISA KEV:** 1
- **New in 2026:** 3
- **CWE catalog version:** 4.21

## Description

The product does not initialize critical variables.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity, Other | Unexpected State, Quality Degradation, Varies by Context | The execution environment might use unexpected values. The uninitialized data may be invalid, causing logic errors within the program. In some cases, this could result in a security problem. |

## Potential mitigations

### Implementation (Attack Surface Reduction)

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

### Requirements (Language Selection)

Choose a language that is not susceptible to these issues.

## Detection methods

### 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 function attempts to extract a pair of numbers from a user-supplied string.

Bad code:

```c
void parse_data(char *untrusted_input){
    int m, n, error;
    error = sscanf(untrusted_input, "%d:%d", &m, &n);
    if ( EOF == error ){
        die("Did not specify integer value. Die evil hacker!\n");
    }
    /* proceed assuming n and m are initialized correctly */
}
```

Attack code:

```
123:
```

### Example 2

Here, an uninitialized field in a Java class is used in a seldom-called method, which would cause a NullPointerException to be thrown.

Bad code:

```java
private User user;
public void someMethod() {

    // Do something interesting.
    ...

    // Throws NPE if user hasn't been properly initialized.
    String username = user.getName();
}
```

### Example 3

This code first authenticates a user, then allows a delete command if the user is an administrator.

Bad code:

```php
if (authenticate($username,$password) && setAdmin($username)){
    $isAdmin = true;
}
/.../

if ($isAdmin){
    deleteUser($userToDelete);
}
```

The $isAdmin variable is set to true if the user is an admin, but is uninitialized otherwise. If PHP's register\_globals feature is enabled, an attacker can set uninitialized variables like $isAdmin to arbitrary values, in this case gaining administrator privileges by setting $isAdmin to true.

### Example 4

In the following Java code the BankManager class uses the user variable of the class User to allow authorized users to perform bank manager tasks. The user variable is initialized within the method setUser that retrieves the User from the User database. The user is then authenticated as unauthorized user through the method authenticateUser.

Bad code:

```java
public class BankManager {

    // user allowed to perform bank manager tasks
    private User user = null;
    private boolean isUserAuthentic = false;

    // constructor for BankManager class
    public BankManager() {
        ...
    }

    // retrieve user from database of users
    public User getUserFromUserDatabase(String username){
        ...
    }

    // set user variable using username
    public void setUser(String username) {
        this.user = getUserFromUserDatabase(username);
    }

    // authenticate user
    public boolean authenticateUser(String username, String password) {
        if (username.equals(user.getUsername()) && password.equals(user.getPassword())) {
            isUserAuthentic = true;
        }
        return isUserAuthentic;
    }

    // methods for performing bank manager tasks
    ...
}
```

Good code:

```java
public class BankManager {

    // user allowed to perform bank manager tasks
    private User user = null;
    private boolean isUserAuthentic = false;

    // constructor for BankManager class
    public BankManager(String username) {
        user = getUserFromUserDatabase(username);
    }

    // retrieve user from database of users
    public User getUserFromUserDatabase(String username) {...}

    // authenticate user
    public boolean authenticateUser(String username, String password) {
        if (user == null) {
            System.out.println("Cannot find user " + username);
        }
        else {
            if (password.equals(user.getPassword())) {
                isUserAuthentic = true;
            }
        }
        return isUserAuthentic;
    }

        // methods for performing bank manager tasks
        ...

}
```

However, if the method setUser is not called before authenticateUser then the user variable will not have been initialized and will result in a NullPointerException. The code should verify that the user variable has been initialized before it is used, as in the following code.

### Example 5

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);
```

### Example 6

Consider the following merchant server application as implemented in \[REF-1475\]. It receives card payment information (orderPgData instance in OrderPgData.java) from the payment gateway (such as PayPal). The next step is to complete the payment (finalizeOrder() in Main.java). The merchant server validates the amount (validateAmount() in OrderPgData.java), and if the validation is successful, then the payment is completed.

Bad code:

```java
File: OrderPgData.java

public class OrderPgData {
    String PgType;
    int productPrice;
    int paymentAmount;
    private boolean isPaymentAmountTampered;
        public boolean getIsPaymentAmountTampered() {
            return this.isPaymentAmountTampered;
        }
    ...
public void validateAmount() {
    ... [sets this.setIsPaymentAmountTampered to true or false depending on whether the product price matches the payment amount]
}
```

Bad code:

```java
File: PgServiceResolver.java

public class PgServiceResolver {
    public OrderPgData getOrderPgDataByPgType(String pgType, int productPrice, int paymentAmount) {
        ...
        switch(pgType) {
            case "card":
                System.out.println("In "+pgType+" payment logic, orderPgData does not verify whether the product amount and payment amount have been tampered with.");
                break;
            case "paypal":
                System.out.println("In "+pgType+" payment logic, orderPgData verifies whether the product amount and payment amount have been tampered with.");
                orderPgData.validateAmount();
                break;
            }
            ...
```

Bad code:

```java
File: Main.java

public class Main {
    public static void main(String[] args) {
        String pgType = "card"; // or paypal
        int productPrice = 100;
        int paymentAmount = 10;
        PgServiceResolver pgServiceResolver = new PgServiceResolver();
        OrderPgData orderPgData = pgServiceResolver.getOrderPgDataByPgType(pgType, productPrice, paymentAmount);
        finalizeOrder(orderPgData);
    }
    private static void finalizeOrder(OrderPgData orderPgData) {
        if (orderPgData.getIsPaymentAmountTampered()) {
            System.out.println("The attacker tampered with the payment amount, but product payment is canceled.");
        } else {
            ... /* the product payment is completed */
        }
    }
}
```

Good code:

```java
File: OrderPgData.java
...
    private boolean isPaymentAmountTampered = true;
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2020-6078 | Chain: The return value of a function returning a pointer is not checked for success (CWE-252) resulting in the later use of an uninitialized variable (CWE-456) and a null pointer dereference (CWE-476) |
| CVE-2019-3836 | Chain: secure communications library does not initialize a local variable for a data structure (CWE-456), leading to access of an uninitialized pointer (CWE-824). |
| CVE-2018-14641 | Chain: C union member is not initialized (CWE-456), leading to access of invalid pointer (CWE-824) |
| CVE-2009-2692 | Chain: Use of an unimplemented network socket operation pointing to an uninitialized handler function (CWE-456) causes a crash because of a null pointer dereference (CWE-476). |
| CVE-2020-20739 | A variable that has its value set in a conditional statement is sometimes used when the conditional fails, sometimes causing data leakage |
| CVE-2005-2978 | Product uses uninitialized variables for size and index, leading to resultant buffer overflow. |
| CVE-2005-2109 | Internal variable in PHP application is not initialized, allowing external modification. |
| CVE-2005-2193 | Array variable not initialized in PHP application, leading to resultant SQL injection. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-46300 | net: skbuff: preserve shared-frag marker during coalescing | high | 7.8 | - | Yes | 2026-05-23 |
| CVE-2025-10547 | CVE-2025-10547 | critical | 9.8 | - | No | 2025-10-03 |
| CVE-2024-32878 | Use of Uninitialized Variable Vulnerability in llama.cpp | high | 8.8 | - | No | 2024-04-26 |
| CVE-2023-20226 | Cisco IOS XE Software Application Quality of Experience and Unified Threat Defense Denial of Service Vulnerability | high | 8.6 | - | No | 2023-09-27 |
| CVE-2024-9780 | Missing Initialization of a Variable in Wireshark | high | 7.8 | - | No | 2024-10-10 |
| CVE-2023-49062 | - | high | 7.5 | - | No | 2023-11-28 |
| CVE-2019-3836 | gnutls: invalid pointer access upon receiving async handshake messages | high | 7.5 | - | No | 2019-04-01 |
| CVE-2021-34703 | Cisco IOS and IOS XE Software Link Layer Discovery Protocol Denial of Service Vulnerability | medium | 6.8 | - | No | 2021-09-23 |
| CVE-2018-14641 | kernel: a bug in ip\_frag\_reasm() can cause a crash in ip\_do\_fragment() | medium | 6.5 | - | No | 2018-09-18 |
| CVE-2021-40403 | gerbv: pick-and-place rotation parsing use of uninitialized variable vulnerability | medium | 6.3 | - | No | 2022-02-04 |
| CVE-2026-130463 | Missing Initialization of a Variable in Wireshark | medium | 5.5 | - | No | 2026-11-20 |
| CVE-2026-133624 | Missing Initialization of a Variable in Wireshark | medium | 5.5 | - | No | 2026-11-20 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-665](https://radicalnotion.ai/cwe/cwe-665) | Improper Initialization |
| Parent | [CWE-909](https://radicalnotion.ai/cwe/cwe-909) | Missing Initialization of Resource |
| Can precede | [CWE-89](https://radicalnotion.ai/cwe/cwe-89) | Improper Neutralization of Special Elements used in an SQL Command |
| Can precede | [CWE-98](https://radicalnotion.ai/cwe/cwe-98) | Improper Control of Filename for Include/Require Statement in PHP Program |
| Can precede | [CWE-120](https://radicalnotion.ai/cwe/cwe-120) | Buffer Copy without Checking Size of Input |
| Can precede | [CWE-457](https://radicalnotion.ai/cwe/cwe-457) | Use of Uninitialized Variable |
| Related | [CWE-454](https://radicalnotion.ai/cwe/cwe-454) | External Initialization of Trusted Variables or Data Stores |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Missing Initialization | - | - |
| Software Fault Patterns | Glitch in computation | SFP1 | - |
| CERT C Secure Coding | Set errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure | ERR30-C | CWE More Abstract |
| SEI CERT Perl Coding Standard | Always initialize local variables | DCL04-PL | Exact |
| SEI CERT Perl Coding Standard | Declare identifiers before using them | DCL33-PL | Imprecise |
| OMG ASCSM | - | ASCSM-CWE-456 | - |
| OMG ASCRM | - | ASCRM-CWE-456 | - |

## Frequently asked questions

### What is CWE-456?

The product does not initialize critical variables.

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

14 recorded CVEs are attributed to CWE-456, including CVE-2026-46300, CVE-2025-10547 and CVE-2024-32878. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-456?

Ensure that critical variables are initialized before first use.

### How is CWE-456 detected?

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

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

Exploiting CWE-456 can lead to: Unexpected State, Quality Degradation, Varies by Context.

### Is CWE-456 actively exploited?

Yes. 1 CWE-456 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 14 recorded CVEs.

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

---

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