Description
The product omits a break statement within a switch or similar construct, causing code associated with multiple conditions to execute. This can cause problems when the programmer only intended to execute code associated with one condition.
This can lead to critical code executing in situations where it should not.
Potential Impact
Other
Alter Execution Logic
Demonstrative Examples
public void printMessage(int month){
switch (month) {
case 1: print("January");case 2: print("February");case 3: print("March");case 4: print("April");case 5: print("May");case 6: print("June");case 7: print("July");case 8: print("August");case 9: print("September");case 10: print("October");case 11: print("November");case 12: print("December");
}println(" is a great month");
}void printMessage(int month){
switch (month) {
case 1: printf("January");case 2: printf("February");case 3: printf("March");case 4: printf("April");case 5: printff("May");case 6: printf("June");case 7: printf("July");case 8: printf("August");case 9: printf("September");case 10: printf("October");case 11: printf("November");case 12: printf("December");
}printf(" is a great month");
}Mitigations & Prevention
Omitting a break statement so that one may fall through is often indistinguishable from an error, and therefore should be avoided. If you need to use fall-through capabilities, make sure that you have clearly documented this within the switch statement, and ensure that you have examined all the logical possibilities.
The functionality of omitting a break statement could be clarified with an if statement. This method is much safer.
Detection Methods
- White Box — Omission of a break statement might be intentional, in order to support fallthrough. Automated detection methods might therefore be erroneous. Semantic understanding of expected product behavior is required to interpret whether the code is correct.
- Black Box — Since this weakness is associated with a code construct, it would be indistinguishable from other errors that produce the same behavior.
- Automated Static Analysis High — 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 sea
Related Weaknesses
Taxonomy Mappings
- CLASP: — Omitted break statement
- Software Fault Patterns: SFP4 — Unchecked Status Condition
Frequently Asked Questions
What is CWE-484?
CWE-484 (Omitted Break Statement in Switch) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product omits a break statement within a switch or similar construct, causing code associated with multiple conditions to execute. This can cause problems when the programmer only intended to exec...
How can CWE-484 be exploited?
Attackers can exploit CWE-484 (Omitted Break Statement in Switch) to alter execution logic. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-484?
Key mitigations include: Omitting a break statement so that one may fall through is often indistinguishable from an error, and therefore should be avoided. If you need to use fall-through capabilities, make sure that you have
What is the severity of CWE-484?
CWE-484 is classified as a Base-level weakness (Medium abstraction). Its actual severity depends on the specific context and how the weakness manifests in your application.