CWE一覧に戻る
CWE-481

比較の代わりに割り当てる

Assigning instead of Comparing
脆弱性 レビュー中
JA

比較のつもりが、代入のために演算子を使用している。

多くの言語では、compare文は代入文と見た目が非常に近く、しばしば混同される。このバグは一般的にタイプミスの結果であり、通常はプログラムの実行に明らかな問題を引き起こします。比較がif文の中にある場合、if文は通常、述語の右辺の値を評価します。

EN

The code uses an operator for assignment when the intention was to perform a comparison.

In many languages the compare statement is very close in appearance to the assignment statement and are often confused. This bug is generally the result of a typo and usually causes obvious problems with program execution. If the comparison is in an if statement, the if statement will usually evaluate the value of the right-hand side of the predicate.

Scope: Other / Impact: Alter Execution Logic
Many IDEs and static analysis products will detect this problem.
Place constants on the left. If one attempts to assign a constant with a variable, the compiler will produce an error.
MITRE公式ページ — CWE-481