{"@ID": "908", "@Name": "Use of Uninitialized Resource", "@Abstraction": "Base", "@Structure": "Simple", "@Status": "Incomplete", "Description": "The product uses or accesses a resource that has not been initialized.", "Extended_Description": "When a resource has not been properly initialized, the product may behave unexpectedly. This may lead to a crash or invalid memory access, but the consequences vary depending on the type of resource and how it is used within the product.", "Related_Weaknesses": {"Related_Weakness": [{"@Nature": "ChildOf", "@CWE_ID": "665", "@View_ID": "1000", "@Ordinal": "Primary"}, {"@Nature": "ChildOf", "@CWE_ID": "665", "@View_ID": "1003", "@Ordinal": "Primary"}]}, "Weakness_Ordinalities": {"Weakness_Ordinality": [{"Ordinality": "Primary"}, {"Ordinality": "Resultant"}]}, "Applicable_Platforms": {"Language": {"@Class": "Not Language-Specific", "@Prevalence": "Undetermined"}}, "Modes_Of_Introduction": {"Introduction": {"Phase": "Implementation"}}, "Likelihood_Of_Exploit": "Medium", "Common_Consequences": {"Consequence": [{"Scope": "Confidentiality", "Impact": ["Read Memory", "Read Application Data"], "Note": "When reusing a resource such as memory or a program variable, the original contents of that resource may not be cleared before it is sent to an untrusted party."}, {"Scope": "Availability", "Impact": "DoS: Crash, Exit, or Restart", "Note": "The uninitialized resource may contain values that cause program flow to change in ways that the programmer did not intend."}]}, "Detection_Methods": {"Detection_Method": {"@Detection_Method_ID": "DM-14", "Method": "Automated Static Analysis", "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"}}, "Potential_Mitigations": {"Mitigation": [{"Phase": "Implementation", "Description": "Explicitly initialize the resource before use. If this is performed through an API function or standard procedure, follow all required steps."}, {"Phase": "Implementation", "Description": "Pay close attention to complex conditionals that affect initialization, since some branches might not perform the initialization."}, {"Phase": "Implementation", "Description": "Avoid race conditions (CWE-362) during initialization routines."}, {"Phase": "Build and Compilation", "Description": "Run or compile the product with settings that generate warnings about uninitialized variables or data."}]}, "Demonstrative_Examples": {"Demonstrative_Example": [{"@Demonstrative_Example_ID": "DX-105", "Intro_Text": "Here, a boolean initiailized field is consulted to ensure that initialization tasks are only completed once. However, the field is mistakenly set to true during static initialization, so the initialization code is never reached.", "Example_Code": {"@Nature": "Bad", "@Language": "Java", "xhtml:div": {"xhtml:br": null, "xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:div": {"@style": "margin-left:1em;", "xhtml:div": {"xhtml:br": [null, null, null, null], "xhtml:i": "// perform initialization tasks", "#text": "...\n                                 initialized = true;"}}, "#text": "if (!initialized) {}"}}, "#text": "private boolean initialized = true;public void someMethod() {"}}}, {"@Demonstrative_Example_ID": "DX-54", "Intro_Text": "The following code intends to limit certain operations to the administrator only.", "Example_Code": {"@Nature": "Bad", "@Language": "Perl", "xhtml:div": {"xhtml:br": [null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "#text": "$uid = ExtractUserID($state);"}, {"@style": "margin-left:1em;", "#text": "DoAdminThings();"}], "xhtml:i": "# do stuff", "#text": "$username = GetCurrentUser();$state = GetStateData($username);if (defined($state)) {}\n                     \n                     \n                     if ($uid == 0) {}"}}, "Body_Text": "If the application is unable to extract the state information - say, due to a database timeout - then the $uid variable will not be explicitly set by the programmer. This will cause $uid to be regarded as equivalent to \"0\" in the conditional, allowing the original user to perform administrator actions. Even if the attacker cannot directly influence the state data, unexpected errors could cause incorrect privileges to be assigned to a user just by accident."}, {"@Demonstrative_Example_ID": "DX-106", "Intro_Text": "The following code intends to concatenate a string to a variable and print the string.", "Example_Code": {"@Nature": "Bad", "@Language": "C", "xhtml:div": {"xhtml:br": [null, null], "#text": "char str[20];strcat(str, \"hello world\");printf(\"%s\", str);"}}, "Body_Text": ["This might seem innocent enough, but str was not initialized, so it contains random memory. As a result, str[0] might not contain the null terminator, so the copy might start at an offset other than 0. The consequences can vary, depending on the underlying memory.", "If a null terminator is found before str[8], then some bytes of random garbage will be printed before the \"hello world\" string. The memory might contain sensitive information from previous uses, such as a password (which might occur as a result of CWE-14 or CWE-244). In this example, it might not be a big deal, but consider what could happen if large amounts of memory are printed out before the null terminator is found.", "If a null terminator isn't found before str[8], then a buffer overflow could occur, since strcat will first look for the null terminator, then copy 12 bytes starting with that location. Alternately, a buffer over-read might occur (CWE-126) if a null terminator isn't found before the end of the memory segment is reached, leading to a segmentation fault and crash."]}, {"@Demonstrative_Example_ID": "DX-144", "Intro_Text": "This example will leave test_string in an\n\t\t\t  unknown condition when i is the same value as err_val,\n\t\t\t  because test_string is not initialized\n\t\t\t  (CWE-456). Depending on where this code segment appears\n\t\t\t  (e.g. within a function body), test_string might be\n\t\t\t  random if it is stored on the heap or stack. If the\n\t\t\t  variable is declared in static memory, it might be zero\n\t\t\t  or NULL. Compiler optimization might contribute to the\n\t\t\t  unpredictability of this address.", "Example_Code": [{"@Nature": "Bad", "@Language": "C", "xhtml:br": [null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "#text": "test_string = \"Hello World!\";"}, "#text": "char *test_string;\n                if (i != err_val)\n                {\n                \n                }\n                printf(\"%s\", test_string);"}, {"@Nature": "Good", "@Language": "C", "xhtml:br": [null, null, null, null], "xhtml:div": {"@style": "margin-left:1em;", "#text": "test_string = \"Hello World!\";"}, "#text": "char *test_string = \"Done at the beginning\";\n\t\t\t\tif (i != err_val)\n\t\t\t\t{\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\tprintf(\"%s\", test_string);"}, {"@Nature": "Good", "@Language": "C", "xhtml:br": [null, null, null, null, null, null], "xhtml:div": [{"@style": "margin-left:1em;", "#text": "test_string = \"Hello World!\";"}, {"@style": "margin-left:1em;", "#text": "test_string = \"Done on the other side!\";"}], "#text": "char *test_string;\n\t\t\t\tif (i != err_val)\n\t\t\t\t{\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\n\t\t\t\t}\n\t\t\t\tprintf(\"%s\", test_string);"}], "Body_Text": [{"xhtml:p": ["When the printf() is reached,\n              test_string might be an unexpected address, so the\n              printf might print junk strings (CWE-457).", "To fix this code, there are a couple approaches to\n\t\t\t  making sure that test_string has been properly set once\n\t\t\t  it reaches the printf().", "One solution would be to set test_string to an\n\t\t\t  acceptable default before the conditional:"]}, "Another solution is to ensure that each\n\t\t\t  branch of the conditional - including the default/else\n\t\t\t  branch - could ensure that test_string is set:"]}]}, "Observed_Examples": {"Observed_Example": [{"Reference": "CVE-2019-9805", "Description": "Chain: Creation of the packet client occurs before initialization is complete (CWE-696) resulting in a read from uninitialized memory (CWE-908), causing memory corruption.", "Link": "https://www.cve.org/CVERecord?id=CVE-2019-9805"}, {"Reference": "CVE-2008-4197", "Description": "Use of uninitialized memory may allow code execution.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-4197"}, {"Reference": "CVE-2008-2934", "Description": "Free of an uninitialized pointer leads to crash and possible code execution.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-2934"}, {"Reference": "CVE-2008-0063", "Description": "Product does not clear memory contents when generating an error message, leading to information leak.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-0063"}, {"Reference": "CVE-2008-0062", "Description": "Lack of initialization triggers NULL pointer dereference or double-free.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-0062"}, {"Reference": "CVE-2008-0081", "Description": "Uninitialized variable leads to code execution in popular desktop application.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-0081"}, {"Reference": "CVE-2008-3688", "Description": "Chain: Uninitialized variable leads to infinite loop.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-3688"}, {"Reference": "CVE-2008-3475", "Description": "Chain: Improper initialization leads to memory corruption.", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-3475"}, {"Reference": "CVE-2005-1036", "Description": "Chain: Bypass of access restrictions due to improper authorization (CWE-862) of a user results from an improperly initialized (CWE-909) I/O permission bitmap", "Link": "https://www.cve.org/CVERecord?id=CVE-2005-1036"}, {"Reference": "CVE-2008-3597", "Description": "Chain: game server can access player data structures before initialization has happened leading to NULL dereference", "Link": "https://www.cve.org/CVERecord?id=CVE-2008-3597"}, {"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)", "Link": "https://www.cve.org/CVERecord?id=CVE-2009-2692"}, {"Reference": "CVE-2009-0949", "Description": "Chain: improper initialization of memory can lead to NULL dereference", "Link": "https://www.cve.org/CVERecord?id=CVE-2009-0949"}, {"Reference": "CVE-2009-3620", "Description": "Chain: some unprivileged ioctls do not verify that a structure has been initialized before invocation, leading to NULL dereference", "Link": "https://www.cve.org/CVERecord?id=CVE-2009-3620"}]}, "Taxonomy_Mappings": {"Taxonomy_Mapping": {"@Taxonomy_Name": "CERT C Secure Coding", "Entry_ID": "EXP33-C", "Entry_Name": "Do not read uninitialized memory", "Mapping_Fit": "CWE More Abstract"}}, "References": {"Reference": {"@External_Reference_ID": "REF-436"}}, "Mapping_Notes": {"Usage": "Allowed", "Rationale": "This CWE entry is at the Base 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.", "Reasons": {"Reason": {"@Type": "Acceptable-Use"}}}, "Content_History": {"Submission": {"Submission_Name": "CWE Content Team", "Submission_Organization": "MITRE", "Submission_Date": "2012-12-21", "Submission_Version": "2.4", "Submission_ReleaseDate": "2013-02-21", "Submission_Comment": "New weakness based on discussion on the CWE research list in December 2012."}, "Modification": [{"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2017-11-08", "Modification_Version": "3.0", "Modification_ReleaseDate": "2017-11-08", "Modification_Comment": "updated Taxonomy_Mappings"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2019-01-03", "Modification_Version": "3.2", "Modification_ReleaseDate": "2019-01-03", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-02-24", "Modification_Version": "4.0", "Modification_ReleaseDate": "2020-02-24", "Modification_Comment": "updated Description, Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-08-20", "Modification_Version": "4.2", "Modification_ReleaseDate": "2020-08-20", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2020-12-10", "Modification_Version": "4.3", "Modification_ReleaseDate": "2020-12-10", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2021-03-15", "Modification_Version": "4.4", "Modification_ReleaseDate": "2021-03-15", "Modification_Comment": "updated Demonstrative_Examples, Observed_Examples"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-01-31", "Modification_Version": "4.10", "Modification_ReleaseDate": "2023-01-31", "Modification_Comment": "updated Description, Potential_Mitigations"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-04-27", "Modification_Version": "4.11", "Modification_ReleaseDate": "2023-04-27", "Modification_Comment": "updated Relationships"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2023-06-29", "Modification_Version": "4.12", "Modification_ReleaseDate": "2023-06-29", "Modification_Comment": "updated Mapping_Notes"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-09-09", "Modification_Version": "4.18", "Modification_ReleaseDate": "2025-09-09", "Modification_Comment": "updated References"}, {"Modification_Name": "CWE Content Team", "Modification_Organization": "MITRE", "Modification_Date": "2025-12-11", "Modification_Version": "4.19", "Modification_ReleaseDate": "2025-12-11", "Modification_Comment": "updated Detection_Factors, Observed_Examples"}]}}
