JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


ALLOC.SIZE.SUBUFLOW : 割り当てサイズの減算アンダーフロー

要旨

チェックされていない減算によるメモリ割り当てサイズの計算は、 整数アンダーフローを起こし予期せず割り当てブロックサイズが大きくなる危険性があります。

(注:減算アンダーフローがメモリ割り当て以外の命令で使用するサイズの計算に影響する場合は、 代わりに (サイズの減算アンダーフロー) が適用されます)

プロパティ

クラス名 Subtraction Underflow of Allocation Size
日本語クラス名 割り当てサイズの減算アンダーフロー
クラス分類 セキュリティ (security)
ニーモニック ALLOC.SIZE.SUBUFLOW
カテゴリー
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
  MisraC++2023:8.20.1 An unsigned arithmetic operation with constant operands should not wrap
CWE CWE:128 Wrap-around Error
  CWE:131 Incorrect Calculation of Buffer Size
  CWE:190 Integer Overflow or Wraparound
  CWE:191 Integer Underflow (Wrap or Wraparound)
  CWE:680 Integer Overflow to Buffer Overflow
TS17961 TS17961:5.45-taintsink Tainted, potentially mutilated, or out-of-domain integer values are used in a restricted sink
CERT-C CERT-C:INT08-C Verify that all integer values are in range
  CERT-C:INT18-C Evaluate integer expressions in a larger size before comparing or assigning to that size
  CERT-C:INT30-C Ensure that unsigned integer operations do not wrap
  CERT-C:INT32-C Ensure that operations on signed integers do not result in overflow
  CERT-C:MEM35-C Allocate sufficient memory for an object
JSF++ JSF++:203 Evaluation of expressions shall not lead to overflow/underflow (unless required algorithmically and then should be heavily documented).
  JSF++:212 Underflow or overflow functioning shall not be depended on in any special way.
DISA-6r1 DISA-6r1:V-222612 The application must not be vulnerable to overflow attacks.
DISA-5r3 DISA-5r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-4r3 DISA-4r3:V-70277 The application must not be vulnerable to overflow attacks.
DISA-3r10 DISA-3r10:V-16808 The designer will ensure the application is not vulnerable to integer arithmetic issues.
OWASP-2017 OWASP-2017:A8 Insecure deserialization
OWASP-2021 OWASP-2021:A8 Software and data integrity failures
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Subtraction Underflow of Allocation Size"

#include <stdlib.h>

int do_subuflow_alloc(int x, int y)
{
    char *p =  malloc(x-y);  /* 'Subtraction Underflow of Allocation Size'  warning issued here. */
    int rv = 0;
    if (p){
        rv = 1;
    free(p);
    }
    return rv;
}

ワーニングを引き起こす関数

Subtraction Underflow of Allocation Size warnings can be triggered by any function treated as an allocator by CodeSonar:

割り当てサイズの加算オーバーフロー、割り当てサイズの乗算オーバーフロー、割り当てサイズの減算アンダーフロー、割り当てサイズの切り捨ての各クラスは、同じトリガー関数が適用されます。

注釈

CodeSonar はワーニングの実行パス (core path) に入る前に与えられる整数値の制約は考慮していません。

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.