CERT C Rule Enforcement
(2016 Edition plus website 28 April 2020)
POSIX Rules are listed separately
ENFORCEMENT FOR KW 2023.3
Total Number of Rules
Total Number of ‘Not Statically Enforceable’ Rules (Assisted/Unassisted)
Total Number of Enforceable Rules (a-b)
Total Number of Enforced Rules
Total Number of Unenforced Rules
Enforce Rules Percentage (d/c)
Unenforced Rules Percentage (e/c)
Rule 01. Preprocessors (PRE)
Do not create a universal character name through concatenation.
Avoid side effects in arguments to unsafe macros.
Do not use preprocessor directives in invocations of function-like macros.
Rule 02. Declarations and Initialization(DCL)
Declare objects with appropriate storage durations.
Declare identifiers before using them.
Do not declare an identifier with conflicting linkage classifications.
Do not declare or define a reserved identifier.
Use the correct syntax when declaring a flexible array member.
Avoid information leakage when passing a structure across a trust boundary.
Do not create incompatible declarations of the same function or object.
Do not declare variables inside a switch statement before the first case label.
Rule 03. Expressions (EXP)
Do not depend on the order of evaluation for side effects.
Do not access a volatile object through a nonvolatile reference.
Do not read uninitialized memory.
Do not dereference null pointers.
Do not modify objects with temporary lifetime.
Do not cast pointers into more strictly aligned pointer types.
Call functions with the correct number and type of arguments.
Do not access a variable through a pointer of an incompatible type.
Do not modify constant objects.
Do not compare padding data.
Avoid undefined behavior when using restrict-qualified pointers.
Do not rely on side effects in operands to sizeof, _Alignof, or _Generic.
Do not perform assignments in selection statements.
Do not use a bitwise operator with a Boolean-like operand.
Do not call va_arg with an argument of the incorrect type.
Rule 04. Integers (INT)
Ensure that unsigned integer operations do not wrap.
Ensure that integer conversions do not result in lost or misinterpreted data.
Ensure that operations on signed integers do not result in overflow.
Ensure that division and remainder operations do not result in divide-by-zero errors.
Do 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.
Use correct integer precisions.
Converting a pointer to integer or integer to pointer.
Rule 05. Floating Point (FLP)
Do not use floating-point variables as loop counters.
Prevent or detect domain and range errors in math functions.
Ensure that floating-point conversions are within range of the new type.
Preserve precision when converting integral values to floating-point type.
Do not use object representations to compare floating-point values.
Rule 06. Arrays (ARR)
Do not form or use out-of-bounds pointers or array subscripts.
Ensure size arguments for variable length arrays are in a valid range.
Do not subtract or compare two pointers that do not refer to the same array.
Do not add or subtract an integer to a pointer to a non-array object.
Guarantee that library functions do not form invalid pointers.
Do not add or subtract a scaled integer to a pointer.
Rule 07. Characters and String (STR)
Do not attempt to modify string literals.
Guarantee that storage for strings has sufficient space for character data and the null terminator.
Do not pass a non-null-terminated character sequence to a library function that expects a string.
Cast characters to unsigned char before converting to larger integer sizes.
Arguments to character-handling functions must be representable as an unsigned char.
Do not confuse narrow and wide character strings and functions.
Rule 08. Memory Management (MEM)
Do not access freed memory.
Free dynamically allocated memory when no longer needed.
Allocate and copy structures containing a flexible array member dynamically.
Only free memory allocated dynamically.
Allocate sufficient memory for an object.
Do not modify the alignment of objects by calling realloc().
Rule 09. Input Output (FIO)
Exclude user input from format strings.
Do not perform operations on devices that are only appropriate for files.
Distinguish between characters read from a file and EOF or WEOF.
Do not assume that fgets() or fgetws() returns a nonempty string when successful.
Do not copy a FILE object.
Do not alternately input and output from a stream without an intervening flush or positioning call.
Reset strings on fgets() or fgetws() failure.
Do not call getc(), putc(), getwc(), or putwc() with a stream argument that has side effects.
Close files when they are no longer needed.
Only use values for fsetpos() that are returned from fgetpos().
Avoid TOCTOU race conditions while accessing files.
Do not access a closed file.
Use valid format strings.
Rule 10. Environment (ENV)
Do not modify the object referenced by the return value of certain functions.
Do not rely on an environment pointer following an operation that may invalidate it.
All exit handlers must return normally.
Do not call system().
Do not store pointers returned by certain functions.
Rule 11. Signals (SIG)
Call only asynchronous-safe functions within signal handlers.
Do not access shared objects in signal handlers.
Do not call signal() from within interruptible signal handlers.
Do not return from a computational exception signal handler.
Rule 12. Error Handling (ERR)
Set errno to zero before calling a library function known to set errno, and check errno only after the function returns a value indicating failure.
Do not rely on indeterminate values of errno.
Detect and handle standard library errors.
Detect errors when converting a string to a number.
Rule 14. Concurrency (CON)
Clean up thread-specific storage.
Do not destroy a mutex while it is locked.
Prevent data races when accessing bit-fields from multiple threads.
Avoid race conditions when using library functions.
Declare objects shared between threads with appropriate storage durations.
Avoid deadlock by locking in a predefined order.
Wrap functions that can spuriously wake up in a loop.
Do not call signal() in a multithreaded program.
Preserve thread safety and liveness when using condition variables.
Do not join or detach a thread that was previously joined or detached.
Do not refer to an atomic variable twice in an expression.
Wrap functions that can fail spuriously in a loop.
Do not allow data races in multithreaded code.
Rule 48. Miscellaneous (MISC)
Do not use the rand() function for generating pseudorandom numbers.
Properly seed pseudorandom number generators.
Do not pass invalid data to the asctime() function.
Ensure that control never reaches the end of a non-void function.
Do not treat a predefined identifier as an object if it might only be implemented as a macro.
Do not call va_arg() on a va_list that has an indeterminate value.
Do not violate constraints.
Never hard code sensitive information.
Rule 50. POSIX(POS)
Use the readlink() function properly.
Do not call putenv() with a pointer to an automatic variable as the argument.
Avoid race conditions while checking for the existence of a symbolic link.
Observe correct revocation order while relinquishing privileges.
Ensure that privilege relinquishment is successful.
Beware of race conditions when using fork and file descriptors.
Use the correct byte ordering when transferring data between systems.
Do not use signals to terminate threads.
Do not use threads that can be canceled asynchronously.
Do not unlock or destroy another POSIX thread's mutex.
When data must be accessed by multiple threads, provide a mutex and guarantee no adjacent data is also accessed.
Declare objects shared between POSIX threads with appropriate storage durations.
Avoid deadlock with POSIX threads by locking in predefined order.
Do not perform operations that can block while holding a POSIX lock.
Do not use more than one mutex for concurrent waiting operations on a condition variable.
Detect and handle POSIX library errors.