结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: Medium
The program 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.
cwe_Nature: ChildOf cwe_CWE_ID: 710 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 670 cwe_View_ID: 1000
Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'PHP', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Other | Alter Execution Logic | This weakness can cause unintended logic to be executed and other unexpected application behavior. |
策略:
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.
In both of these examples, a message is printed based on the month passed into the function:
bad Java
bad C
Both examples do not use a break statement after each case, which leads to unintended fall-through behavior. For example, calling "printMessage(10)" will result in the text "OctoberNovemberDecember is a great month" being printed.
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Omitted break statement | ||
Software Fault Patterns | SFP4 | Unchecked Status Condition |