[metadata]
id = "SIG31-C"
type = "rule"
category = "SIG"
number = 31
title = "Do not access shared objects in signal handlers"
description = """
Accessing or modifying shared objects in signal handlers can result in race
conditions that can leave data in an inconsistent state. The two exceptions (C
Standard, 5.1.2.3, paragraph 5) to this rule are the ability to read from and
write to lock-free atomic objects and variables of typevolatile sig_atomic_t.
Accessing any other type of object from a signal handler isundefined behavior.
(Seeundefined behavior 131.) The need for thevolatilekeyword is described
inDCL22-C. Use volatile for data that cannot be cached. The typesig_atomic_tis
the integer type of an object that can be accessed as an atomic entity even in
the presence of asynchronous interrupts. The type
ofsig_atomic_tisimplementation-defined, though it provides some guarantees.
Integer values ranging fromSIG_ATOMIC_MINthroughSIG_ATOMIC_MAX, inclusive, may
be safely stored to a variable of the type. In addition, whensig_atomic_tis a
signed integer type,SIG_ATOMIC_MINmust be no greater than−127andSIG_ATOMIC_MAXno
less than127. Otherwise,SIG_ATOMIC_MINmust be0andSIG_ATOMIC_MAXmust be no less
than255. The macrosSIG_ATOMIC_MINandSIG_ATOMIC_MAXare defined in the
header<stdint.h>.
"""
severity = "High"
likelihood = "Likely"
priority = "P18"
level = "L1"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 05, 2025"
[rules.cert_c.SIG31-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/SIG31-C.+Do+not+access+shared+objects+in+signal+handlers"
cwe = ["CWE-364", "CWE-662", "CWE-828"]