Description
The product accidentally uses the wrong operator, which changes the logic in security-relevant ways.
These types of errors are generally the result of a typo by the programmer.
Potential Impact
Other
Alter Execution Logic
Demonstrative Examples
int isValid(int value) {if (value=100) {printf("Value is valid\n");return(1);}printf("Value is not valid\n");return(0);}bool isValid(int value) {if (value=100) {Console.WriteLine("Value is valid.");return true;}Console.WriteLine("Value is not valid.");return false;}#define SIZE 50int *tos, *p1, stack[SIZE];
void push(int i) {
p1++;if(p1==(tos+SIZE)) {
// Print stack overflow error message and exit
}*p1 == i;
}
int pop(void) {
if(p1==tos) {
// Print stack underflow error message and exit
}p1--;return *(p1+1);
}
int main(int argc, char *argv[]) {
// initialize tos and p1 to point to the top of stack
tos = stack;p1 = stack;
// code to add and remove items from stack
...return 0;
}module csr_regfile #(
...
// check that we actually want to enter debug depending on the privilege level we are currently in
unique case (priv_lvl_o)
riscv::PRIV_LVL_M: begin
debug_mode_d = dcsr_q.ebreakm;
...
riscv::PRIV_LVL_U: begin
debug_mode_d = dcsr_q.ebreaku;
...
assign priv_lvl_o = (debug_mode_q || umode_i) ? riscv::PRIV_LVL_M : priv_lvl_q;
...
debug_mode_q <= debug_mode_d;
...module csr_regfile #(
...
// check that we actually want to enter debug depending on the privilege level we are currently in
unique case (priv_lvl_o)
riscv::PRIV_LVL_M: begin
debug_mode_d = dcsr_q.ebreakm;
...
riscv::PRIV_LVL_U: begin
debug_mode_d = dcsr_q.ebreaku;
...
assign priv_lvl_o = (debug_mode_q && umode_i) ? riscv::PRIV_LVL_M : priv_lvl_q;
...
debug_mode_q <= debug_mode_d;
...Detection Methods
- Automated Static Analysis — This weakness can be found easily using static analysis. However in some cases an operator might appear to be incorrect, but is actually correct and reflects unusual logic within the program.
- Manual Static Analysis — This weakness can be found easily using static analysis. However in some cases an operator might appear to be incorrect, but is actually correct and reflects unusual logic within the program.
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2022-3979 | Chain: data visualization program written in PHP uses the "!=" operator instead of the type-strict "!==" operator (CWE-480) when validating hash values, potentially leading to an incorrect type conver |
| CVE-2021-3116 | Chain: Python-based HTTP Proxy server uses the wrong boolean operators (CWE-480) causing an incorrect comparison (CWE-697) that identifies an authN failure if all three conditions are met instead of |
Related Weaknesses
Taxonomy Mappings
- CLASP: — Using the wrong operator
- CERT C Secure Coding: EXP45-C — Do not perform assignments in selection statements
- CERT C Secure Coding: EXP46-C — Do not use a bitwise operator with a Boolean-like operand
- Software Fault Patterns: SFP1 — Glitch in Computation
Frequently Asked Questions
What is CWE-480?
CWE-480 (Use of Incorrect Operator) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Base-level weakness. The product accidentally uses the wrong operator, which changes the logic in security-relevant ways.
How can CWE-480 be exploited?
Attackers can exploit CWE-480 (Use of Incorrect Operator) to alter execution logic. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-480?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-480?
CWE-480 is classified as a Base-level weakness (Medium abstraction). It has been observed in 2 real-world CVEs.