CWE一覧に戻る
CWE-839

最小値チェックなしの数値範囲比較

Numeric Range Comparison Without Minimum Check
脆弱性 作成中
JA

この製品は、値が最大値以下であることを確認するが、値が最小値以上であることは確認しない。

入力検証チェックでは、値が正であると仮定し、最大値のみをチェックすることがあります。値が負であるにもかかわらず、コードがその値を正であると仮定している場合、 エラーを発生させる可能性があります。負の値がメモリ割り当て、配列アクセス、バッファ・アクセスなどに使用された場合、このエラーはセキュリ ティに影響を及ぼす可能性があります。最終的に、このエラーはバッファ・オーバーフローや他のタイプのメモリ破壊につながる可能性がある。

正の値だけのコンテキストで負数を使用すると、他の種類のリソースにセキュリティ上の影響を及ぼす可能性があります。例えば、ショッピング・カートは、ユーザが 10 個以上の商品を要求していないことをチェックするかもしれません が、-3 個の商品の要求は、アプリケーションに負の価格を計算させ、攻撃者のアカウントに入金させるかもしれません。

EN

The product checks a value to ensure that it is less than or equal to a maximum, but it does not also verify that the value is greater than or equal to the minimum.

Some products use signed integers or floats even when their values are only expected to be positive or 0. An input validation check might assume that the value is positive, and only check for the maximum value. If the value is negative, but the code assumes that the value is positive, this can produce an error. The error may have security consequences if the negative value is used for memory allocation, array access, buffer access, etc. Ultimately, the error could lead to a buffer overflow or other type of memory corruption.

The use of a negative number in a positive-only context could have security implications for other types of resources. For example, a shopping cart might check that the user is not requesting more than 10 items, but a request for -3 items could cause the application to calculate a negative price and credit the attacker's account.

Scope: Integrity, Confidentiality, Availability / Impact: Modify Application Data; Execute Unauthorized Code or Commands
Scope: Availability / Impact: DoS: Resource Consumption (Other)
Scope: Confidentiality, Integrity / Impact: Modify Memory; Read Memory
If the number to be used is always expected to be positive, change the variable type from signed to unsigned or size_t.
If the number to be used could have a negative value based on the specification (thus requiring a signed value), but the number should only be positive to preserve code correctness, then include a check to ensure that the value is positive.
MITRE公式ページ — CWE-839