メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

CERT C ルールと推奨事項

Polyspace® でサポートされる CERT C 標準ルールと推奨事項のリストと説明

CERT C はソフトウェア開発者向けの一連のコード ガイドラインです。C 言語での安全なコーディングを中心としています。このガイドラインは、実行時に予期しない結果を招き、セキュリティの脆弱性が外部にさらされる可能性のある未定義の動作を含む構文を取り除くのに役立ちます。継続的に開発中の CERT C の Web サイトに、各種のルールと推奨事項が掲載されています。CERT C ルールと推奨事項に対する Polyspace の対応範囲を確認するには、Polyspace でのコーディング規約のサポートを参照してください。[SEI CERT-C をチェック] (-cert-c) 解析オプションを使用して、このルールと推奨事項のサブセットを有効にします。

Polyspace 結果

すべて展開する

Rule 01.プリプロセッサ (PRE)

CERT C: Rule PRE30-C連結からユニバーサル文字名を作成しない
CERT C: Rule PRE31-C安全でないマクロに対する引数の二次的影響を避ける
CERT C: Rule PRE32-C関数形式のマクロの呼び出しでプリプロセッサ命令を使用しない

Rule 02.宣言と初期化 (DCL)

CERT C: Rule DCL30-CDeclare objects with appropriate storage durations
CERT C: Rule DCL31-CDeclare identifiers before using them
CERT C: Rule DCL36-C競合するリンクの分類をもつ識別子を宣言しない
CERT C: Rule DCL37-C予約済みの識別子を宣言または定義しない
CERT C: Rule DCL38-Cフレキシブル配列メンバーの宣言時に正しい構文を使用する
CERT C: Rule DCL39-CAvoid information leakage in structure padding
CERT C: Rule DCL40-CDo not create incompatible declarations of the same function or object
CERT C: Rule DCL41-Cswitch ステートメント内の最初の case ラベルの前で変数を宣言しない

Rule 03.式 (EXP)

CERT C: Rule EXP30-C二次的影響に関して評価の順序に依存しない
CERT C: Rule EXP32-CDo not access a volatile object through a nonvolatile reference
CERT C: Rule EXP33-CDo not read uninitialized memory
CERT C: Rule EXP34-CDo not dereference null pointers
CERT C: Rule EXP35-C有効期間が一時的なオブジェクトを変更しない
CERT C: Rule EXP36-CDo not cast pointers into more strictly aligned pointer types
CERT C: Rule EXP37-CCall functions with the correct number and type of arguments
CERT C: Rule EXP39-CDo not access a variable through a pointer of an incompatible type
CERT C: Rule EXP40-CDo not modify constant objects
CERT C: Rule EXP42-Cパディング データを比較しない
CERT C: Rule EXP43-CAvoid undefined behavior when using restrict-qualified pointers
CERT C: Rule EXP44-Csizeof、_Alignof、または _Generic のオペランドの二次的影響に依存しない
CERT C: Rule EXP45-CDo not perform assignments in selection statements
CERT C: Rule EXP46-Cboolean 形式のオペランドと一緒にビット演算子を使用しない
CERT C: Rule EXP47-C無効な型の引数を使用して va_arg を呼び出さない

Rule 04.整数 (INT)

CERT C: Rule INT30-CEnsure that unsigned integer operations do not wrap
CERT C: Rule INT31-CEnsure that integer conversions do not result in lost or misinterpreted data
CERT C: Rule INT32-CEnsure that operations on signed integers do not result in overflow
CERT C: Rule INT33-CEnsure that division and remainder operations do not result in divide-by-zero errors
CERT C: Rule INT34-CDo not shift an expression by a negative number of bits or by greater than or equal to the number of bits that exist in the operand
CERT C: Rule INT35-CUse correct integer precisions
CERT C: Rule INT36-CConverting a pointer to integer or integer to pointer

Rule 05.浮動小数点 (FLP)

CERT C: Rule FLP30-C浮動小数点変数をループ カウンターとして使用しない
CERT C: Rule FLP32-CPrevent or detect domain and range errors in math functions
CERT C: Rule FLP34-CEnsure that floating-point conversions are within range of the new type
CERT C: Rule FLP36-CPreserve precision when converting integral values to floating-point type
CERT C: Rule FLP37-C浮動小数点値の比較にオブジェクト表現を使用しない

Rule 06.配列 (ARR)

CERT C: Rule ARR30-CDo not form or use out-of-bounds pointers or array subscripts
CERT C: Rule ARR32-CEnsure size arguments for variable length arrays are in a valid range
CERT C: Rule ARR36-C同じ配列を参照しない 2 つのポインターを減算したり比較したりしない
CERT C: Rule ARR37-CDo not add or subtract an integer to a pointer to a non-array object
CERT C: Rule ARR38-CGuarantee that library functions do not form invalid pointers
CERT C: Rule ARR39-CDo not add or subtract a scaled integer to a pointer

Rule 07.文字と文字列 (STR)

CERT C: Rule STR30-CDo not attempt to modify string literals
CERT C: Rule STR31-CGuarantee that storage for strings has sufficient space for character data and the null terminator
CERT C: Rule STR32-CDo not pass a non-null-terminated character sequence to a library function that expects a string
CERT C: Rule STR34-CCast characters to unsigned char before converting to larger integer sizes
CERT C: Rule STR37-C文字処理関数の引数は符号なし char で表現できなければならない
CERT C: Rule STR38-Cナロー文字列およびワイド文字列と関数を混同しない

Rule 08.メモリ管理 (MEM)

CERT C: Rule MEM30-CDo not access freed memory
CERT C: Rule MEM31-CFree dynamically allocated memory when no longer needed
CERT C: Rule MEM33-Cフレキシブル配列メンバーを含む構造体を動的に割り当ておよびコピーする
CERT C: Rule MEM34-COnly free memory allocated dynamically
CERT C: Rule MEM35-CAllocate sufficient memory for an object
CERT C: Rule MEM36-Crealloc() を呼び出してオブジェクトのアライメントを変更しない

Rule 09.入出力 (FIO)

CERT C: Rule FIO30-CExclude user input from format strings
CERT C: Rule FIO32-CDo not perform operations on devices that are only appropriate for files
CERT C: Rule FIO34-CDistinguish between characters read from a file and EOF or WEOF
CERT C: Rule FIO37-CDo not assume that fgets() or fgetws() returns a nonempty string when successful
CERT C: Rule FIO38-CFILE オブジェクトをコピーしない
CERT C: Rule FIO39-Cフラッシュまたは位置付け呼び出しの介在なしでのストリームからの入出力を交互実行しない
CERT C: Rule FIO40-Cfgets() または fgetws() 失敗時に文字列をリセットする
CERT C: Rule FIO41-C二次的影響があるストリーム引数を使用して getc()、putc()、getwc()、putwc() を呼び出さない
CERT C: Rule FIO42-CClose files when they are no longer needed
CERT C: Rule FIO44-Cfgetpos() から返された fsetpos() の値のみを使用する
CERT C: Rule FIO45-CAvoid TOCTOU race conditions while accessing files
CERT C: Rule FIO46-CDo not access a closed file
CERT C: Rule FIO47-CUse valid format strings

Rule 10.環境 (ENV)

CERT C: Rule ENV30-CDo not modify the object referenced by the return value of certain functions
CERT C: Rule ENV31-C環境ポインターを無効にする可能性のある操作の後にその環境ポインターに依存しない
CERT C: Rule ENV32-Cすべての終了ハンドラーは正常に戻らなければならない
CERT C: Rule ENV33-CDo not call system()
CERT C: Rule ENV34-CDo not store pointers returned by certain functions

Rule 11.信号 (SIG)

CERT C: Rule SIG30-C信号ハンドラー内から非同期安全な関数のみを呼び出す
CERT C: Rule SIG31-C信号ハンドラー内の共有オブジェクトにアクセスしない
CERT C: Rule SIG34-C中断可能な信号ハンドラー内から signal() を呼び出さない
CERT C: Rule SIG35-C計算例外の信号ハンドラーから値を返さない

Rule 12.エラーの取り扱い (ERR)

CERT C: Rule ERR30-CSet errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure
CERT C: Rule ERR32-Cerrno の不確定の値に依存しない
CERT C: Rule ERR33-C標準ライブラリのエラーを検出および処理する
CERT C: Rule ERR34-C文字列を数値に変換する際にエラーを検出する

Rule 14.同時実行 (CON)

CERT C: Rule CON30-CClean up thread-specific storage
CERT C: Rule CON31-Cロック中はミューテックスを破棄しない
CERT C: Rule CON32-C複数のスレッドからビット フィールドにアクセス中のデータ レースを回避する
CERT C: Rule CON33-CAvoid race conditions when using library functions
CERT C: Rule CON34-CDeclare objects shared between threads with appropriate storage durations
CERT C:Rule CON35-CAvoid deadlock by locking in a predefined order
CERT C: Rule CON36-CWrap functions that can spuriously wake up in a loop
CERT C: Rule CON37-CDo not call signal() in a multithreaded program
CERT C: Rule CON38-C条件変数の使用時にスレッドの安全性と存続性を維持する
CERT C:Rule CON39-C以前に結合または分離されたスレッドを結合したり分離したりしない
CERT C: Rule CON40-CDo not refer to an atomic variable twice in an expression
CERT C: Rule CON41-CWrap functions that can fail spuriously in a loop
CERT C: Rule CON43-CDo not allow data races in multithreaded code

Rule 48.その他 (MSC)

CERT C: Rule MSC30-CDo not use the rand() function for generating pseudorandom numbers
CERT C: Rule MSC32-CProperly seed pseudorandom number generators
CERT C: Rule MSC33-CDo not pass invalid data to the asctime() function
CERT C: Rule MSC37-CEnsure that control never reaches the end of a non-void function
CERT C: Rule MSC38-Cマクロとして実装されている可能性のある定義済みの識別子をオブジェクトとして扱わない
CERT C: Rule MSC39-CDo not call va_arg() on a va_list that has an indeterminate value
CERT C: Rule MSC40-C制約に違反しない
CERT C:Rule MSC41-CNever hard code sensitive information

Rule 50.POSIX (POS)

CERT C: Rule POS30-CUse the readlink() function properly
CERT C:Rule POS34-C引数として自動変数を指すポインターを使用して putenv() を呼び出さない
CERT C: Rule POS35-CAvoid race conditions while checking for the existence of a symbolic link
CERT C: Rule POS36-C権限を放棄する場合は正しい取り消し順序に従う
CERT C: Rule POS37-C権限の放棄が必ず正常に行われるようにする
CERT C: Rule POS38-Cフォークとファイル記述子を使用する際に競合状態に注意する
CERT C: Rule POS39-Cシステム間でデータを転送する際に正しいバイト順を使用する
CERT C: Rule POS44-CDo not use signals to terminate threads
CERT C: Rule POS47-C非同期でキャンセル可能なスレッドを使用しない
CERT C:Rule POS48-C別の POSIX スレッドのミューテックスをロック解除または破棄しない
CERT C: Rule POS49-CWhen data must be accessed by multiple threads, provide a mutex and guarantee no adjacent data is also accessed
CERT C: Rule POS50-CDeclare objects shared between POSIX threads with appropriate storage durations
CERT C:Rule POS51-CAvoid deadlock with POSIX threads by locking in predefined order
CERT C: Rule POS52-CDo not perform operations that can block while holding a POSIX lock
CERT C: Rule POS53-C条件変数の同時待機操作に複数のミューテックスを使用しない
CERT C: Rule POS54-CPOSIX ライブラリのエラーを検出および処理する

Rule 51.Microsoft Windows (WIN)

CERT C: Rule WIN30-C割り当て関数と割り当て解除関数を適切にペアにする

Rec.01.プリプロセッサ (PRE)

CERT C: Rec.PRE00-C関数形式のマクロよりインライン関数または静的関数を選ぶ
CERT C: Rec.PRE01-Cマクロ内ではパラメーター名を囲むかっこを使用する
CERT C: Rec.PRE03-CPrefer typedefs to defines for encoding non-pointer type (R2024a 以降)
CERT C:Rec.PRE04-CDo not reuse a standard header file name (R2025a 以降)
CERT C:Rec.PRE05-CUnderstand macro replacement when concatenating tokens or performing stringification (R2024b 以降)
CERT C:Rec.PRE06-Cヘッダー ファイルをインクルード ガード内に囲む
CERT C: Rec.PRE07-C疑問符を繰り返し使用することを避ける
CERT C: Rec.PRE08-CGuarantee that header file names are unique (R2024a 以降)
CERT C: Rec.PRE09-Cセキュリティ保護された関数を非推奨または使用されなくなった関数と置き換えない
CERT C:Rec.PRE10-Cマルチステートメント マクロを do-while ループでラップする
CERT C:Rec.PRE11-Cマクロ定義をセミコロンで終了しない
CERT C: Rec.PRE12-CDo not define unsafe macros (R2024a 以降)

Rec.02.宣言と初期化 (DCL)

CERT C: Rec.DCL00-CConst-qualify immutable objects
CERT C: Rec.DCL01-CDo not reuse variable names in subscopes
CERT C: Rec.DCL02-C視覚的に区別できる識別子を使用する
CERT C: Rec.DCL06-CUse meaningful symbolic constants to represent literal values
CERT C: Rec.DCL07-C適切な型情報を関数宣言子に含める
CERT C: Rec.DCL10-C可変個引数関数のライターと呼び出し元の間のコントラクトを維持する
CERT C: Rec.DCL11-CUnderstand the type issues associated with variadic functions
CERT C: Rec.DCL12-C抽象データ型は不透明な型を使用して実装する
CERT C: Rec.DCL13-C当該関数によって変更されない値へのポインターである関数パラメーターは const として宣言する
CERT C: Rec.DCL15-C外部リンクを必要としないファイル スコープ オブジェクトまたは関数は static として宣言する
CERT C: Rec.DCL16-C'l' ではなく 'L' を使用して long 値を示す
CERT C: Rec.DCL18-C10 進数値を指定する際に整数定数を 0 では始めない
CERT C: Rec.DCL19-C変数と関数のスコープは最小化する
CERT C:Rec.DCL21-CUnderstand the storage of compound literals (R2024b 以降)
CERT C:Rec.DCL22-CUse volatile for data that cannot be cached
CERT C: Rec.DCL23-C相互に可視の識別子は一意になることを保証する

Rec.03.式 (EXP)

CERT C: Rec.EXP00-CUse parentheses for precedence of operation
CERT C:Rec.EXP03-CDo not assume the size of a structure is the sum of the sizes of its members (R2025a 以降)
CERT C:Rec.EXP05-CDo not cast away a const qualification
CERT C:Rec.EXP07-CDo not diminish the benefits of constants by assuming their values in expressions (R2024a 以降)
CERT C:Rec.EXP08-CEnsure pointer arithmetic is used correctly
CERT C: Rec.EXP09-C型または変数のサイズを判別する場合は sizeof を使用する
CERT C: Rec.EXP10-C部分式の評価の順序または二次的影響が発生する順序には依存しない
CERT C:Rec.EXP11-CDo not make assumptions regarding the layout of structures with bit-fields (R2024b 以降)
CERT C:Rec.EXP12-C関数から返された値を無視しない
CERT C: Rec.EXP13-CTreat relational and equality operators as if they were nonassociative
CERT C: Rec.EXP15-Cif、for、または while ステートメントと同じ行にセミコロンを配置しない
CERT C:Rec.EXP19-Cif、for または while ステートメントの本体では中かっこを使用する

Rec.04.整数 (INT)

CERT C: Rec.INT00-CUnderstand the data model used by your implementation(s)
CERT C: Rec.INT02-CUnderstand integer conversion rules
CERT C: Rec.INT04-CEnforce limits on integer values originating from tainted sources
CERT C: Rec.INT07-C数値の場合は符号付きまたは符号なしの char 型のみを明示的に使用する
CERT C: Rec.INT08-CVerify that all integer values are in range
CERT C: Rec.INT09-C列挙定数は必ず一意値にマッピングされるようにする
CERT C: Rec.INT10-CDo not assume a positive remainder when using the % operator
CERT C: Rec.INT12-C式で使用する場合にプレーンな int ビットフィールドの型について仮定を行わない
CERT C: Rec.INT13-CUse bitwise operators only on unsigned operands
CERT C: Rec.INT14-C同じデータに対してビット演算と算術演算の実行を避ける
CERT C: Rec.INT18-CEvaluate integer expressions in a larger size before comparing or assigning to that size

Rec.05.浮動小数点 (FLP)

CERT C: Rec.FLP00-C浮動小数点数の制限事項を理解する
CERT C: Rec.FLP02-C精度の高い計算が必要な場合は浮動小数点数の使用を避ける
CERT C: Rec.FLP03-CDetect and handle floating-point errors
CERT C: Rec.FLP06-CConvert integers to floating point for floating-point operations

Rec.06.配列 (ARR)

CERT C: Rec.ARR01-CDo not apply the sizeof operator to a pointer when taking the size of an array
CERT C: Rec.ARR02-CExplicitly specify array bounds, even if implicitly defined by an initializer

Rec.07.文字と文字列 (STR)

CERT C: Rec.STR02-CSanitize data passed to complex subsystems
CERT C: Rec.STR03-CDo not inadvertently truncate a string
CERT C:Rec.STR06-CDo not assume that strtok() leaves the parse string unchanged (R2025a 以降)
CERT C:Rec.STR07-C文字列操作での範囲チェック インターフェイスの使用
CERT C: Rec.STR11-CDo not specify the bound of a character array initialized with a string literal

Rec.08.メモリ管理 (MEM)

CERT C: Rec.MEM00-CAllocate and free memory in the same module, at the same level of abstraction
CERT C: Rec.MEM01-Cfree() の直後にポインターに新しい値を保存する
CERT C: Rec.MEM02-CImmediately cast the result of a memory allocation function call into a pointer to the allocated type
CERT C: Rec.MEM03-CClear sensitive information stored in reusable resources
CERT C: Rec.MEM04-CBeware of zero-length allocations
CERT C: Rec.MEM05-CAvoid large stack allocations
CERT C: Rec.MEM06-CEnsure that sensitive data is not written out to disk
CERT C: Rec.MEM11-CDo not assume infinite heap space
CERT C: Rec.MEM12-Cリソースの使用時や解放時にエラーが発生して関数を出る場合は、goto 連鎖の使用を検討する

Rec.09.入出力 (FIO)

CERT C: Rec.FIO02-CCanonicalize path names originating from tainted sources
CERT C:Rec.FIO03-CDo not make assumptions about fopen() and file creation (R2024a 以降)
CERT C:Rec.FIO06-CCreate files with appropriate access permissions (R2024b 以降)
CERT C:Rec.FIO08-CTake care when calling remove() on an open file (R2024b 以降)
CERT C:Rec.FIO10-CTake care when using the rename() function (R2024b 以降)
CERT C:Rec.FIO11-CTake care when specifying the mode parameter of fopen()
CERT C: Rec.FIO21-CDo not create temporary files in shared directories
CERT C: Rec.FIO24-C既に開いているファイルを開かない

Rec.10.環境 (ENV)

CERT C: Rec.ENV01-CDo not make assumptions about the size of an environment variable

Rec.12.エラーの取り扱い (ERR)

CERT C: Rec.ERR00-C一貫性のある包括的なエラーの取り扱いポリシーを採用および実装する

Rec.13.Application Programming Interfaces (API)

CERT C: Rec.API04-CProvide a consistent and usable error-checking mechanism

Rec.14.同時実行 (CON)

CERT C: Rec.CON01-CAcquire and release synchronization primitives in the same module, at the same level of abstraction
CERT C: Rec.CON05-CDo not perform operations that can block while holding a lock

Rec.48.その他 (MSC)

CERT C: Rec.MSC01-CStrive for logical completeness
CERT C: Rec.MSC04-Cコメントは一貫性のある読みやすい方法で使用する
CERT C: Rec.MSC12-CDetect and remove code that has no effect or is never executed
CERT C: Rec.MSC13-CDetect and remove unused values
CERT C: Rec.MSC15-CDo not depend on undefined behavior.
CERT C: Rec.MSC17-Ccase ラベルに関連付けるステートメントのすべてのセットを break ステートメントで終了する
CERT C: Rec.MSC18-CBe careful while handling sensitive data, such as passwords, in program code
CERT C: Rec.MSC20-Cswitch ステートメントを使用して複雑なブロックに制御を移行しない
CERT C: Rec.MSC21-CUse robust loop termination conditions
CERT C: Rec.MSC22-CUse the setjmp(), longjmp() facility securely
CERT C: Rec.MSC24-CDo not use deprecated or obsolescent functions

Rec.50.POSIX (POS)

CERT C: Rec.POS05-CLimit access to files by creating a jail

Rec.51.Microsoft Windows (WIN)

CERT C: Rec.WIN00-CBe specific when dynamically loading libraries

トピック