C and C++ Binaries


ALLOC.SIZE.IOFLOW : 割り当てサイズの整数オーバーフロー

要旨

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

一般的に、 割り当てサイズの乗算オーバーフロー (Multiplication Overflow of Allocation Size) の部分集合となります。 但し、C++ の new[] 内で暗黙的に乗算される場合を除きます(この場合は、割り当てサイズの整数オーバーフローを引き起こしますが、割り当てサイズの乗算オーバーフローは引き起こしません)。

プロパティ

クラス名 Integer Overflow of Allocation Size
日本語クラス名 割り当てサイズの整数オーバーフロー
クラス分類 セキュリティ (security)
ニーモニック ALLOC.SIZE.IOFLOW
カテゴリー
MisraC2023 MisraC2023:D.4.11 The validity of values passed to library functions shall be checked
Misra2012 Misra2012:D.4.11 The validity of values passed to library functions shall be checked
Misra2004 Misra2004:20.3 The validity of values passed to library functions shall be checked
CWE CWE:128 Wrap-around Error
  CWE:131 Incorrect Calculation of Buffer Size
  CWE:190 Integer Overflow or Wraparound
  CWE:680 Integer Overflow to Buffer Overflow
TS17961 TS17961:5.29-intoflow 5.29. Overflowing signed integers
  TS17961:5.45-taintsink 5.45. Tainted, potentially mutilated, or out-of-domain integer values are used in a restricted sink
CERT-C CERT-C:ARR32-C Ensure size arguments for variable length arrays are in a valid range
  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 += discard class="Integer Overflow of Allocation Size"

このワーニングを避けるためには、 割り当てサイズの計算値を使用する前に全ての乗算結果をチェックしてください。

#include <cstdlib>

void ioflow(int x, int y, int z){
    int s;
    char *p;

    p = (char *)  malloc(x * y);   /* 'Integer Overflow of Allocation Size' warning issued here */
                                   /* When enabled, 'Multiplication Overflow of Allocation Size' warning also issued here */
    if (!p){return;} else {free(p);}

    s = x * y;
    p = (char *) malloc(s);       /* 'Integer Overflow of Allocation Size' warning issued here */
    if (!p){return;} else {free(p);}

    p = new char[x * y];          /* 'Integer Overflow of Allocation Size' warning issued here */
    delete[] p;

    s = y * z;
    if (s / y == z){
      p = (char *) malloc(s + 1);                             /* ok: multiplication result was checked */
      if (!p){return;} else {free(p);}
    }

    if ( (y*z) / y == z){
      p = (char *) malloc(y*z + 1);  /* 'Integer Overflow of Allocation Size' warning issued here
                                      * - the multiplication operation inside the malloc() argument was not checked
                                      */
      if (!p){return;} else {free(p);}
    }
}

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

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