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++
Binaries


LANG.STRUCT.LOOP.HR : リスクの高いループ

要旨

ループ内でポインタ演算が行われ、そのポインタを介して書き込みを行っているループがあります。

オブジェクトの領域外にポインタが移動を続け、その後書き込む場合以外は問題は起こりませんが、問題が潜在している可能性があります。

通常、CodeSonar は危険な書き込みが実際に起きる場合、適切なクラス [*] のワーニングを検出します。 しかし、まれにオーバーラン/アンダーランを見逃してしまう場合があります。 例えば、到達可能な危険な書き込みを含んだパスを探索する前に SEARCH_BOUND に到達した場合、ワーニングは検出されません。 リスクの高いループワーニングでは、ループ自体が直接原因ではないオーバーランやアンダーランを含むループを検出する可能性があります。

プロパティ

クラス名 High Risk Loop
日本語クラス名 リスクの高いループ
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.LOOP.HR
カテゴリー
CWE CWE:119 Improper Restriction of Operations within the Bounds of a Memory Buffer
CERT-C CERT-C:MSC21-C Use robust loop termination conditions
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="High Risk Loop"

例1: それ自身はオブジェクトの外部に書き込まない、リスクの高いループ

/* Example 1: loop does not write outside an object */
void lang_struct_loop_hr_1(void){
    char buf[10];
    char *p;

    p = buf;
    while (p < buf+10){ /* 'High Risk Loop' warning issued here */
      *p++ = 'a';             /* p is incremented after it is written through, so no overflow here */
    }
    /* If the function wrote through p here after exiting the loop,
     * that would overflow buf.
     */
}

/* Example 2: loop writes outside buf */
void lang_struct_loop_hr_2(void){
    char buf[10];
    char *p;

    p = buf;
    while (p < buf+10){ /* 'High Risk Loop' warning issued here */
        *++p = 'a';     /* 'Buffer Overrun' warning issued here
                         * - p is incremented before it is written through
                         */
    }
}

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

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


[*] バッファオーバーランバッファアンダーラン型オーバーラン型アンダーラン のいずれとなるかは、オブジェクトに書き込まれるかポインタ演算かによって決定されます。

 

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