结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: Low
The programmer accidentally uses the wrong operator, which changes the application logic in security-relevant ways.
These types of errors are generally the result of a typo.
Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Sometimes'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Sometimes'}, {'cwe_Name': 'Perl', 'cwe_Prevalence': 'Sometimes'}, {'cwe_Class': 'Language-Independent', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
Other | Alter Execution Logic | This weakness can cause unintended logic to be executed and other unexpected application behavior. |
The following C/C++ and C# examples attempt to validate an int input parameter against the integer value 100.
bad C
bad C#
However, the expression to be evaluated in the if statement uses the assignment operator "=" rather than the comparison operator "==". The result of using the assignment operator instead of the comparison operator causes the int variable to be reassigned locally and the expression in the if statement will always evaluate to the value on the right hand side of the expression. This will result in the input value not being properly validated, which can cause unexpected results.
The following C/C++ example shows a simple implementation of a stack that includes methods for adding and removing integer values from the stack. The example uses pointers to add and remove integer values to the stack array variable.
bad C
The push method includes an expression to assign the integer value to the location in the stack pointed to by the pointer variable.
However, this expression uses the comparison operator "==" rather than the assignment operator "=". The result of using the comparison operator instead of the assignment operator causes erroneous values to be entered into the stack and can cause unexpected results.
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
CLASP | Using the wrong operator | ||
CERT C Secure Coding | EXP45-C | CWE More Abstract | Do not perform assignments in selection statements |
CERT C Secure Coding | EXP46-C | CWE More Abstract | Do not use a bitwise operator with a Boolean-like operand |