Skip to content

Missing break statement in switch construct

Description

The software 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.

Examples

Insecure Code

c
switch (x) { case 1: printf("one"); case 2: printf("two"); }

Secure Code

c
switch (x) { case 1: printf("one"); break; case 2: printf("two"); break; }

Remediation

Add a break statement after each case in the switch construct to prevent fallthrough.

Rule Details

FieldValue
IDCODE-0227
CategoryGeneric
SeverityMEDIUM
CWECWE-484
ConfidenceLOW
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tags
OWASPN/A

References