1143
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
Potential Mitigations
Phase: Implementation
Ensure that there are no cases unaccounted for when adjusting program flow or values based
on the value of a given variable. In the case of switch style statements, the very simple act
of creating a default case can, if done correctly, mitigate this situation. Often however, the
default case is used simply to represent an assumed option, as opposed to working as a check
for invalid input. This is poor practice and in some cases is as bad as omitting a default case
entirely.
Demonstrative Examples
Example 1:
The following does not properly check the return code in the case where the security_check
function returns a -1 value when an error occurs. If an attacker can supply data that will invoke an
error, the attacker can bypass the security check:
Example Language: C (Bad)
#define FAILED 0
#define PASSED 1
int result;
...
result = security_check(data);
switch (result) {
case FAILED:
printf("Security check failed!\n");
exit(-1);
//Break never reached because of exit()
break;
case PASSED:
printf("Security check passed.\n");
break;
}
// program execution continues...
...
Instead a default label should be used for unaccounted conditions:
Example Language: C (Good)
#define FAILED 0
#define PASSED 1
int result;
...
result = security_check(data);
switch (result) {
case FAILED:
printf("Security check failed!\n");
exit(-1);
//Break never reached because of exit()
break;
CWE Version 4.14
CWE-478: Missing Default Case in Multiple Condition Expression
CWE-478: Missing Default Case in Multiple Condition Expression