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.
Use of Uninitialized Variable
This vulnerability occurs when a program accesses a variable before it has been assigned a value, leading to unpredictable behavior and potential security risks.
What is CWE-457?
Real-world CVEs caused by CWE-457
-
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).
-
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.
-
Uninitialized variable leads to code execution in popular desktop application.
-
Crafted input triggers dereference of an uninitialized object pointer.
-
Crafted audio file triggers crash when an uninitialized variable is used.
-
Uninitialized random seed variable used.
Parcours de l'attaquant étape par étape
- 1
This code prints a greeting using information stored in a POST request:
- 2
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.
- 3
The following switch statement is intended to set the values of the variables aN and bN before they are used:
- 4
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.
- 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.
Vulnerable PHP
This code prints a greeting using information stored in a POST request:
if (isset($_POST['names'])) {
$nameArray = $_POST['names'];
}
echo "Hello " . $nameArray['first']; Secure C
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:
char *test_string = "Done at the beginning";
if (i != err_val)
{
```
test_string = "Hello World!";
}
printf("%s", test_string); How to prevent CWE-457
- Implementation Ensure that critical variables are initialized before first use [REF-1485].
- Build and Compilation 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 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.
How to detect CWE-457
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.)
Plexicus détecte automatiquement CWE-457 et ouvre une PR de correction en moins de 60 secondes.
Codex Remedium analyse chaque commit, identifie cette faiblesse précise et livre une pull request prête à être relue avec le correctif. Pas de tickets. Pas de transferts.
Frequently asked questions
Qu'est-ce que CWE-457 ?
This vulnerability occurs when a program accesses a variable before it has been assigned a value, leading to unpredictable behavior and potential security risks.
Quelle est la gravité de CWE-457 ?
MITRE évalue la probabilité d'exploitation comme Élevée — cette faiblesse est activement exploitée et doit être priorisée pour la remédiation.
Quels langages ou plateformes sont affectés par CWE-457 ?
MITRE lists the following affected platforms: C, C++, Perl, PHP.
Comment puis-je prévenir CWE-457 ?
Ensure that critical variables are initialized before first use [REF-1485]. Most compilers will complain about the use of uninitialized variables if warnings are turned on.
Comment Plexicus détecte et corrige CWE-457 ?
Le moteur SAST de Plexicus reconnaît la signature de flux de données de CWE-457 à chaque commit. Lorsqu'une correspondance est trouvée, notre agent Codex Remedium ouvre une PR de correction avec le code corrigé, les tests et un résumé d'une ligne pour le relecteur.
Où puis-je en savoir plus sur CWE-457 ?
MITRE publie la définition canonique à https://cwe.mitre.org/data/definitions/457.html. Vous pouvez également consulter la documentation OWASP et NIST pour des conseils adjacents.
Weaknesses related to CWE-457
Further reading
- MITRE — CWE-457 officiel https://cwe.mitre.org/data/definitions/457.html
- The CLASP Application Security Process https://cwe.mitre.org/documents/sources/TheCLASPApplicationSecurityProcess.pdf
- Exploiting Uninitialized Data https://web.archive.org/web/20070403193636/http://www.felinemenace.org/~mercy/papers/UBehavior/UBehavior.zip
- MS08-014 : The Case of the Uninitialized Stack Variable Vulnerability https://msrc.microsoft.com/blog/2008/03/ms08-014-the-case-of-the-uninitialized-stack-variable-vulnerability/
- D3FEND: D3-VI Variable Initialization https://d3fend.mitre.org/technique/d3f:VariableInitialization/
Arrêtez de payer par développeur.
Commencez à fermer la boucle.
Plexicus est l'ASPM natif IA qui scanne, filtre, corrige, penteste et explique — de façon autonome. Développeurs illimités, dépôts illimités, actions IA à usage équitable. Vrai niveau gratuit, €269/mo annuel quand vous êtes prêt.