目标达成 感谢每一位支持者 — 我们达成了 100% 目标!

目标: 1000 元 · 已筹: 1000

100.0%

CWE-478 在Switch语句中缺失缺省条件 类漏洞列表 1

CWE-478 在Switch语句中缺失缺省条件 类弱点 1 条 CVE 漏洞汇总,含 AI 中文分析。

CWE-478属于逻辑缺陷漏洞,指代码在多条件表达式(如switch语句)中缺失默认分支。当未处理所有可能输入值时,程序可能基于错误信息做出决策,导致逻辑错误或未定义行为。攻击者可通过构造特定输入触发未覆盖路径,引发数据损坏或逻辑绕过。开发者应确保涵盖所有预期及异常输入,显式添加默认分支以处理未知情况,从而增强代码鲁棒性。

MITRE CWE 官方描述
CWE:CWE-478 多条件表达式中缺少默认分支(Missing Default Case in Multiple Condition Expression) 英文:代码在多条件表达式(如 switch 语句)中缺少默认分支(default case)。 如果多条件表达式(例如 C 语言中的 switch)省略了默认分支,且未考虑或处理所有可能出现的值,则可能导致复杂的逻辑错误及由此产生的弱点。因此,后续决策将基于不准确的信息做出,并引发级联故障(cascading failure)。这种级联故障可能导致各种安全问题,并构成系统的重大故障。
常见影响 (1)
IntegrityVaries by Context, Alter Execution Logic
Depending on the logical circumstances involved, any consequences may result: e.g., issues of confidentiality, authentication, authorization, availability, integrity, accountability, or non-repudiation.
缓解措施 (1)
ImplementationEnsure 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 …
代码示例 (2)
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:
#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... ...
Bad · C
#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; default: printf("Unknown error (%d), exiting...\n",result); exit(-1); }
Good · C
In the following Java example the method getInterestRate retrieves the interest rate for the number of points for a mortgage. The number of points is provided within the input parameter and a switch statement will set the interest rate value to be returned based on the number of points.
public static final String INTEREST_RATE_AT_ZERO_POINTS = "5.00"; public static final String INTEREST_RATE_AT_ONE_POINTS = "4.75"; public static final String INTEREST_RATE_AT_TWO_POINTS = "4.50"; ... public BigDecimal getInterestRate(int points) { BigDecimal result = new BigDecimal(INTEREST_RATE_AT_ZERO_POINTS); switch (points) { case 0: result = new BigDecimal(INTEREST_RATE_AT_ZERO_POINTS); break; case 1: result = new BigDecimal(INTEREST_RATE_AT_ONE_POINTS); break; case 2: result = new BigDecimal(INTEREST_RATE_AT_TWO_POINTS); break; } return result; }
Bad · Java
public static final String INTEREST_RATE_AT_ZERO_POINTS = "5.00"; public static final String INTEREST_RATE_AT_ONE_POINTS = "4.75"; public static final String INTEREST_RATE_AT_TWO_POINTS = "4.50"; ... public BigDecimal getInterestRate(int points) { BigDecimal result = new BigDecimal(INTEREST_RATE_AT_ZERO_POINTS); switch (points) { case 0: result = new BigDecimal(INTEREST_RATE_AT_ZERO_POINTS); break; case 1: result = new BigDecimal(INTEREST_RATE_AT_ONE_POINTS); break; case 2: result = new BigDecimal(INTEREST_RATE_AT_TWO_POINTS); break; default: System.err.println("Invalid value for points, must 
Good · Java
CVE ID标题CVSS风险等级Published
CVE-2026-33064 free5GC 安全漏洞 — free5gc 7.5 -2026-03-20

CWE-478(在Switch语句中缺失缺省条件) 是常见的弱点类别,本平台收录该类弱点关联的 1 条 CVE 漏洞。