Logo
-

Byte Open Security

(ByteOS Network)

Log In

Sign Up

ByteOS

Security
Vulnerability Details
Registries
Custom Views
Weaknesses
Attack Patterns
Filters & Tools
CWE-456:Missing Initialization of a Variable
Weakness ID:456
Version:v4.17
Weakness Name:Missing Initialization of a Variable
Vulnerability Mapping:Allowed
Abstraction:Variant
Structure:Simple
Status:Draft
Likelihood of Exploit:
DetailsContent HistoryObserved CVE ExamplesReports
▼Description

The product does not initialize critical variables, which causes the execution environment to use unexpected values.

▼Extended Description

▼Alternate Terms
▼Relationships
Relevant to the view"Research Concepts - (1000)"
NatureMappingTypeIDName
CanPrecedeAllowedB89Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
CanPrecedeAllowed-with-ReviewB120Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
CanPrecedeAllowedV98Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')
CanPrecedeAllowedV457Use of Uninitialized Variable
ChildOfAllowed-with-ReviewC909Missing Initialization of Resource
ParentOfAllowedB454External Initialization of Trusted Variables or Data Stores
Nature: CanPrecede
Mapping: Allowed
Type: Base
ID: 89
Name: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Nature: CanPrecede
Mapping: Allowed-with-Review
Type: Base
ID: 120
Name: Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Nature: CanPrecede
Mapping: Allowed
Type: Variant
ID: 98
Name: Improper Control of Filename for Include/Require Statement in PHP Program ('PHP Remote File Inclusion')
Nature: CanPrecede
Mapping: Allowed
Type: Variant
ID: 457
Name: Use of Uninitialized Variable
Nature: ChildOf
Mapping: Allowed-with-Review
Type: Class
ID: 909
Name: Missing Initialization of Resource
Nature: ParentOf
Mapping: Allowed
Type: Base
ID: 454
Name: External Initialization of Trusted Variables or Data Stores
▼Memberships
NatureMappingTypeIDName
MemberOfProhibitedC8082010 Top 25 - Weaknesses On the Cusp
MemberOfProhibitedC8672011 Top 25 - Weaknesses On the Cusp
MemberOfProhibitedV884CWE Cross-section
MemberOfProhibitedC998SFP Secondary Cluster: Glitch in Computation
MemberOfProhibitedC1129CISQ Quality Measures (2016) - Reliability
MemberOfProhibitedC1131CISQ Quality Measures (2016) - Security
MemberOfProhibitedC1167SEI CERT C Coding Standard - Guidelines 12. Error Handling (ERR)
MemberOfProhibitedC1180SEI CERT Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL)
MemberOfProhibitedC1416Comprehensive Categorization: Resource Lifecycle Management
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 808
Name: 2010 Top 25 - Weaknesses On the Cusp
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 867
Name: 2011 Top 25 - Weaknesses On the Cusp
Nature: MemberOf
Mapping: Prohibited
Type:View
ID: 884
Name: CWE Cross-section
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 998
Name: SFP Secondary Cluster: Glitch in Computation
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1129
Name: CISQ Quality Measures (2016) - Reliability
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1131
Name: CISQ Quality Measures (2016) - Security
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1167
Name: SEI CERT C Coding Standard - Guidelines 12. Error Handling (ERR)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1180
Name: SEI CERT Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL)
Nature: MemberOf
Mapping: Prohibited
Type:Category
ID: 1416
Name: Comprehensive Categorization: Resource Lifecycle Management
▼Tags
NatureMappingTypeIDName
MemberOfProhibitedBSBOSS-294Not Language-Specific Weaknesses
MemberOfProhibitedBSBOSS-315Unexpected State (impact)
MemberOfProhibitedBSBOSS-325Quality Degradation (impact)
MemberOfProhibitedBSBOSS-326Varies by Context (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-294
Name: Not Language-Specific Weaknesses
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-315
Name: Unexpected State (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-325
Name: Quality Degradation (impact)
Nature: MemberOf
Mapping: Prohibited
Type:BOSSView
ID: BOSS-326
Name: Varies by Context (impact)
▼Relevant To View
Relevant to the view"Weaknesses Addressed by the SEI CERT C Coding Standard - (1154)"
NatureMappingTypeIDName
MemberOfProhibitedC1167SEI CERT C Coding Standard - Guidelines 12. Error Handling (ERR)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1167
Name: SEI CERT C Coding Standard - Guidelines 12. Error Handling (ERR)
Relevant to the view"Weaknesses Addressed by the SEI CERT Perl Coding Standard - (1178)"
NatureMappingTypeIDName
MemberOfProhibitedC1180SEI CERT Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL)
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 1180
Name: SEI CERT Perl Coding Standard - Guidelines 02. Declarations and Initialization (DCL)
Relevant to the view"Software Fault Pattern (SFP) Clusters - (888)"
NatureMappingTypeIDName
MemberOfProhibitedC998SFP Secondary Cluster: Glitch in Computation
Nature: MemberOf
Mapping: Prohibited
Type: Category
ID: 998
Name: SFP Secondary Cluster: Glitch in Computation
▼Background Detail

▼Common Consequences
ScopeLikelihoodImpactNote
IntegrityOtherN/AUnexpected StateQuality DegradationVaries by Context

The uninitialized data may be invalid, causing logic errors within the program. In some cases, this could result in a security problem.

Scope: Integrity, Other
Likelihood: N/A
Impact: Unexpected State, Quality Degradation, Varies by Context
Note:

The uninitialized data may be invalid, causing logic errors within the program. In some cases, this could result in a security problem.

▼Potential Mitigations
Phase:Implementation
Mitigation ID:
Strategy:
Effectiveness:
Description:

Check that critical variables are initialized.

Note:


Phase:Testing
Mitigation ID:
Strategy:
Effectiveness:
Description:

Use a static analysis tool to spot non-initialized variables.

Note:

▼Modes Of Introduction
Phase: Implementation
Note:

N/A

▼Applicable Platforms
Languages
Class: Not Language-Specific(Undetermined Prevalence)
▼Demonstrative Examples
Example 1

This function attempts to extract a pair of numbers from a user-supplied string.

Language: ( code)
N/A

Language: C(Bad code)
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 */* }

Language: ( code)
N/A

This code attempts to extract two integer values out of a formatted, user-supplied input. However, if an attacker were to provide an input of the form:

Language: (Attack code)
123:

Language: ( code)
N/A

then only the m variable will be initialized. Subsequent use of n may result in the use of an uninitialized variable (CWE-457).

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.

Language: ( code)
N/A

Language: Java(Bad code)
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.

Language: ( code)
N/A

Language: PHP(Bad code)
if (authenticate($username,$password) && setAdmin($username)){ $isAdmin = true; } /.../* if ($isAdmin){ deleteUser($userToDelete); }

Language: ( code)
N/A

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.

Language: ( code)
N/A

Language: Java(Bad code)
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* ...}

Language: ( code)
N/A

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.

Language: Java(Good code)
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* ... }

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.

Language: ( code)
N/A

Language: C(Bad code)
char *test_string; if (i != err_val) { test_string = "Hello World!"; } printf("%s", test_string);

Language: ( code)
N/A

When the printf() is reached, test_string might be an unexpected address, so the printf might print junk strings (CWE-457).

To fix this code, there are a couple approaches to making sure that test_string has been properly set once it reaches the printf().

One solution would be to set test_string to an acceptable default before the conditional:

Language: C(Good code)
char *test_string = "Done at the beginning"; if (i != err_val) { test_string = "Hello World!"; } printf("%s", test_string);

Language: ( code)
N/A

Another solution is to ensure that each branch of the conditional - including the default/else branch - could ensure that test_string is set:

Language: C(Good code)
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.

Language: ( code)
N/A

Language: Java(Bad code)
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] }

Language: Java(Bad code)
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; } ...

Language: Java(Bad code)
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 */ } } }

Language: ( code)
N/A

In PgServiceResolver.java, when pgType is "card" indicating a card payment, orderPgData.validateAmount() is not called - that is, the amount is not validated to be the same as the expected price.

Since isPaymentAmountTampered is declared as a private boolean, but it is not initialized, it is forcibly initialized to false by the Java compiler [REF-1476].

If the adversary modifies the price, e.g., changing paymentAmount from 100 to 10, then no validation is performed. Since isPaymentAmountTampered is "false" because of the default initialization, the code finishes processing the payment because it does not believe that the amount has been changed.

Language: ( code)
N/A

This weakness could be addressed by setting the value of isPaymentAmountTampered to true. This is a "secure-by-default" value that reflects a "default deny" policy - i.e., it's assumed that the payment amount is tampered, and only a special validation step can change this assumption.

Language: Java(Good code)
File: OrderPgData.java ... private boolean isPaymentAmountTampered = true;

▼Observed Examples
ReferenceDescription
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.
Reference: CVE-2020-6078
Description:
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)
Reference: CVE-2019-3836
Description:
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).
Reference: CVE-2018-14641
Description:
Chain: C union member is not initialized (CWE-456), leading to access of invalid pointer (CWE-824)
Reference: CVE-2009-2692
Description:
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).
Reference: CVE-2020-20739
Description:
A variable that has its value set in a conditional statement is sometimes used when the conditional fails, sometimes causing data leakage
Reference: CVE-2005-2978
Description:
Product uses uninitialized variables for size and index, leading to resultant buffer overflow.
Reference: CVE-2005-2109
Description:
Internal variable in PHP application is not initialized, allowing external modification.
Reference: CVE-2005-2193
Description:
Array variable not initialized in PHP application, leading to resultant SQL injection.
▼Affected Resources
    ▼Functional Areas
      ▼Weakness Ordinalities
      OrdinalityDescription
      ▼Detection Methods
      Automated Static Analysis
      Detection Method ID:DM-14
      Description:

      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
      Note:

      N/A

      ▼Vulnerability Mapping Notes
      Usage:Allowed
      Reason:Acceptable-Use
      Rationale:

      This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.

      Comments:

      Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

      Suggestions:
      ▼Notes
      Relationship

      This weakness is a major factor in a number of resultant weaknesses, especially in web applications that allow global variable initialization (such as PHP) with libraries that can be directly requested.

      N/A

      Research Gap

      It is highly likely that a large number of resultant weaknesses have missing initialization as a primary factor, but researcher reports generally do not provide this level of detail.

      N/A

      ▼Taxonomy Mappings
      Taxonomy NameEntry IDFitEntry Name
      PLOVERN/AN/AMissing Initialization
      Software Fault PatternsSFP1N/AGlitch in computation
      CERT C Secure CodingERR30-CCWE More AbstractSet errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure
      SEI CERT Perl Coding StandardDCL04-PLExactAlways initialize local variables
      SEI CERT Perl Coding StandardDCL33-PLImpreciseDeclare identifiers before using them
      OMG ASCSMASCSM-CWE-456N/AN/A
      OMG ASCRMASCRM-CWE-456N/AN/A
      Taxonomy Name: PLOVER
      Entry ID: N/A
      Fit: N/A
      Entry Name: Missing Initialization
      Taxonomy Name: Software Fault Patterns
      Entry ID: SFP1
      Fit: N/A
      Entry Name: Glitch in computation
      Taxonomy Name: CERT C Secure Coding
      Entry ID: ERR30-C
      Fit: CWE More Abstract
      Entry Name: 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
      Taxonomy Name: SEI CERT Perl Coding Standard
      Entry ID: DCL04-PL
      Fit: Exact
      Entry Name: Always initialize local variables
      Taxonomy Name: SEI CERT Perl Coding Standard
      Entry ID: DCL33-PL
      Fit: Imprecise
      Entry Name: Declare identifiers before using them
      Taxonomy Name: OMG ASCSM
      Entry ID: ASCSM-CWE-456
      Fit: N/A
      Entry Name: N/A
      Taxonomy Name: OMG ASCRM
      Entry ID: ASCRM-CWE-456
      Fit: N/A
      Entry Name: N/A
      ▼Related Attack Patterns
      IDName
      ▼References
      Reference ID: REF-62
      Title: The Art of Software Security Assessment
      Author: Mark Dowd, John McDonald, Justin Schuh
      Section: Chapter 7, "Variable Initialization", Page 312
      Publication:
      Publisher:Addison Wesley
      Edition:1st Edition
      URL:
      URL Date:
      Day:N/A
      Month:N/A
      Year:2006
      Reference ID: REF-961
      Title: Automated Source Code Reliability Measure (ASCRM)
      Author: Object Management Group (OMG)
      Section: ASCRM-CWE-456
      Publication:
      Publisher:
      Edition:
      URL:http://www.omg.org/spec/ASCRM/1.0/
      URL Date:
      Day:N/A
      Month:01
      Year:2016
      Reference ID: REF-962
      Title: Automated Source Code Security Measure (ASCSM)
      Author: Object Management Group (OMG)
      Section: ASCSM-CWE-456
      Publication:
      Publisher:
      Edition:
      URL:http://www.omg.org/spec/ASCSM/1.0/
      URL Date:
      Day:N/A
      Month:01
      Year:2016
      Reference ID: REF-1475
      Title: uninitialized variable vulnerability - Problem with boolean variables that are forcibly initialized to false by the Java compiler
      Author: windshock
      Section:
      Publication:
      Publisher:
      Edition:
      URL:https://github.com/windshock/uninitialized-variable-vulnerability/blob/main/README.md
      URL Date:2025-04-02
      Day:13
      Month:09
      Year:2022
      Reference ID: REF-1476
      Title: The Java Language Specification, Java SE 7 Edition
      Author: James Gosling, Bill Joy, Guy Steele, Gilad Bracha, Alex Buckley
      Section:
      Publication:
      Publisher:
      Edition:
      URL:https://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5
      URL Date:2025-04-02
      Day:28
      Month:02
      Year:2013
      Details not found