C and C++ Binaries


LANG.STRUCT.RPL : ローカル変数へのポインタ戻し

要旨

関数が、ローカル変数を参照するポインタを返り値としています。

プロパティ

クラス名 Return Pointer to Local
日本語クラス名 ローカル変数へのポインタ戻し
クラス分類 セキュリティ (security)
ニーモニック LANG.STRUCT.RPL
カテゴリー
MisraC2023 MisraC2023:18.6 The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
Misra2012 Misra2012:18.6 The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
AUTOSARC++14 AUTOSARC++14:M7-5-1 A function shall not return a reference or a pointer to an automatic variable (including parameters), defined within the function.
MisraC++2008 MisraC++2008:7-5-1 A function shall not return a reference or a pointer to an automatic variable (including parameters), defined within the function.
MisraC++2023 MisraC++2023:6.8.2 A function must not return a reference or a pointer to a local variable with automatic storage duration
CWE CWE:562 Return of Stack Variable Address
TS17961 TS17961:5.14-nullref 5.14. Dereferencing an out-of-domain pointer
CERT-C CERT-C:DCL30-C Declare objects with appropriate storage durations
CERT-CPP CERT-CPP:EXP53-CPP Do not read uninitialized memory
JSF++ JSF++:70.1 An object shall not be improperly used before its lifetime begins or after its lifetime ends.
  JSF++:111 A function shall not return a pointer or reference to a non-static local object.
  JSF++:173 The address of an object with automatic storage shall not be assigned to an object which persists after the object has ceased to exist.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Return Pointer to Local"

int * lang_struct_rpl(){
    int j = 7;
    return &j; /* 'Return Pointer To Local' warning issued here */
}

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

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