Dataset Viewer
Auto-converted to Parquet Duplicate
language
large_string
page_id
int64
page_url
large_string
chapter
int64
section
int64
rule_id
large_string
title
large_string
intro
large_string
noncompliant_code
large_string
compliant_solution
large_string
risk_assessment
large_string
breadcrumb
large_string
c
87,152,074
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152074
3
13
API00-C
Functions should validate their parameters
Redundant testing by caller and by callee as a style of defensive programming is largely discredited in the C and C++ communities, the main problem being performance. The usual discipline in C and C++ is to require validation on only one side of each interface. Requiring the caller to validate arguments can result in f...
/* Sets some internal state in the library */ extern int setfile(FILE *file); /* Performs some action using the file passed earlier */ extern int usefile(); static FILE *myFile; void setfile(FILE *file) { myFile = file; } void usefile(void) { /* Perform some action here */ } ## Noncompliant Code Example In...
/* Sets some internal state in the library */ extern errno_t setfile(FILE *file); /* Performs some action using the file passed earlier */ extern errno_t usefile(void); static FILE *myFile; errno_t setfile(FILE *file) { if (file && !ferror(file) && !feof(file)) { myFile = file; return 0; } /* Error saf...
## Risk Assessment Failing to validate the parameters in library functions may result in an access violation or a data integrity violation. Such a scenario indicates a flaw in how the library is used by the calling code. However, the library itself may still be the vector by which the calling code's vulnerability is ex...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,151,926
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151926
3
13
API01-C
Avoid laying out strings in memory directly before sensitive data
Strings (both character and wide-character) are often subject to buffer overflows, which will overwrite the memory immediately past the string. Many rules warn against buffer overflows, including . Sometimes the danger of buffer overflows can be minimized by ensuring that arranging memory such that data that might be c...
const size_t String_Size = 20; struct node_s { char name[String_Size]; struct node_s* next; } ## Noncompliant Code Example ## This noncompliant code example stores a set of strings using a linked list: #ffcccc c const size_t String_Size = 20; struct node_s { char name[String_Size]; struct node_s* next; } A buffer ...
const size_t String_Size = 20; struct node_s { struct node_s* next; char name[String_Size]; } const size_t String_Size = 20; struct node_s { struct node_s* next; char* name; } ## Compliant Solution ## This compliant solution creates a linked list of strings but stores thenextpointer before the string: #ccccff...
## Risk Assessment Failure to follow this recommendation can result in memory corruption from buffer overflows, which can easily corrupt data or yield remote code execution. Rule Severity Likelihood Detectable Repairable Priority Level API01-C High Likely Yes No P18 L1 Automated Detection Tool Version Checker Descripti...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,290
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152290
3
13
API02-C
Functions that read or write to or from an array should take an argument to specify the source or target size
Functions that have an array as a parameter should also have an additional parameter that indicates the maximum number of elements that can be stored in the array. That parameter is required to ensure that the function does not access memory outside the bounds of the array and adversely influence program execution. It ...
char *strncpy(char * restrict s1, const char * restrict s2, size_t n); char *strncat(char * restrict s1, const char * restrict s2, size_t n); ## Noncompliant Code Example It is not necessary to go beyond the standard C library to find examples that violate this recommendation because the C language often prioritizes p...
char *improved_strncpy(char * restrict s1, size_t s1count, const char * restrict s2, size_t s2count, size_t n); char *improved_strncat(char * restrict s1, size_t s1count, const char * restrict s2, size_t s2count, size_t n); ## Compliant Solution The C strncpy() and strncat() functions could be improved by adding eleme...
## Risk Assessment Failure to follow this recommendation can result in improper memory accesses and buffer overflows that are detrimental to the correct and continued execution of the program. Rule Severity Likelihood Detectable Repairable Priority Level API02-C High Likely Yes No P18 L1 Automated Detection Tool Versio...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,287
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152287
3
13
API03-C
Create consistent interfaces and capabilities across related functions
Related functions, such as those that make up a library, should provide consistent and usable interfaces. Ralph Waldo Emerson said, "A foolish consistency is the hobgoblin of little minds," but inconsistencies in functional interfaces or behavior can lead to erroneous use, so we understand this to be a "wise consistenc...
int fputs(const char * restrict s, FILE * restrict stream); int fprintf(FILE * restrict stream, const char * restrict format, ...); #include <stdio.h> #define fputs(X,Y) fputs(Y,X) ## Noncompliant Code Example (Interface) It is not necessary to go beyond the standard C library to find examples of inconsistent interf...
/* Initialization of pthread attribute objects */ int pthread_condattr_init(pthread_condattr_t *); int pthread_mutexattr_init(pthread_mutexattr_t *); int pthread_rwlockattr_init(pthread_rwlockattr_t *); ... /* Initialization of pthread objects using attributes */ int pthread_cond_init(pthread_cond_t * restrict, const p...
## Risk Assessment Failure to maintain consistency in interfaces and capabilities across functions can result in type errors in the program. Rule Severity Likelihood Detectable Repairable Priority Level API03-C Medium Unlikely No No P2 L3 Related Vulnerabilities Search for vulnerabilities resulting from the violation o...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,244
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152244
3
13
API04-C
Provide a consistent and usable error-checking mechanism
Functions should provide consistent and usable error-checking mechanisms. Complex interfaces are sometimes ignored by programmers, resulting in code that is not error checked. Inconsistent interfaces are frequently misused and difficult to use, resulting in lower-quality code and higher development costs.
char *dir, *file, pname[MAXPATHLEN]; /* ... */ if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) { /* Handle source-string-too long error */ } ## Noncompliant Code Example (strlcpy()) The strlcpy() function copies a null-terminated source string to a destination array. It is designed to be a safer, more con...
errno_t retValue; string_m dest, source; /* ... */ if (retValue = strcpy_m(dest, source)) { fprintf(stderr, "Error %d from strcpy_m.\n", retValue); } ## Compliant Solution (strcpy_m()) The managed string library [ Burch 2006 ] handles errors by consistently returning the status code in the function return val...
## Risk Assessment Failure to provide a consistent and usable error-checking mechanism can result in type errors in the program. Rule Severity Likelihood Detectable Repairable Priority Level API04-C Medium Unlikely No No P2 L3 Automated Detection Tool Version Checker Description error-information-unused error-informati...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,031
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152031
3
13
API05-C
Use conformant array parameters
Traditionally, C arrays are declared with an index that is either a fixed constant or empty. An array with a fixed constant index indicates to the compiler how much space to reserve for the array. An array declaration with an empty index is an incomplete type and indicates that the variable references a pointer to an a...
void my_memset(char* p, size_t n, char v) { memset( p, v, n); } void my_memset(char p[n], size_t n, char v) { memset( p, v, n); } ## Noncompliant Code Example This code example provides a function that wraps a call to the standard memset() function and has a similar set of arguments. However, although this functi...
void my_memset(size_t n; char p[n], size_t n, char v) { memset(p, v, n); } void my_memset(size_t n, char p[n], char v) { memset(p, v, n); } ## Compliant Solution (GCC) This compliant solution uses a GNU extension to forward declare the size_t variable n before using it in the subsequent array declaration. Consequ...
## Risk Assessment Failing to specify conformant array dimensions increases the likelihood that another developer will invoke the function with out-of-range integers, which could cause an out-of-bounds memory read or write. Rule Severity Likelihood Detectable Repairable Priority Level API05-C High Probable Yes No P12 L...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,337
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152337
3
13
API07-C
Enforce type safety
Upon return, functions should guarantee that any object returned by the function, or any modified value referenced by a pointer argument, is a valid object of function return type or argument type. Otherwise, type errors can occur in the program. A good example is the null-terminated byte string type in C. If a string ...
char *source; char a[NTBS_SIZE]; /* ... */ if (source) { char* b = strncpy(a, source, 5); // b == a } else { /* Handle null string condition */ } ## Noncompliant Code Example The standard strncpy() function does not guarantee that the resulting string is null-terminated. If there is no null character in the first ...
char *source; char a[NTBS_SIZE]; /* ... */ if (source) { errno_t err = strncpy_s(a, sizeof(a), source, 5); if (err != 0) { /* Handle error */ } } else { /* Handle null string condition */ } ## Compliant Solution (strncpy_s(), C11 Annex K) The C11 Annex K strncpy_s() function copies up to n characters from ...
## Risk Assessment Failure to enforce type safety can result in type errors in the program. Rule Severity Likelihood Detectable Repairable Priority Level API07-C Medium Unlikely No No P2 L3 Automated Detection Tool Version Checker Description LANG.CAST.VALUE LANG.CAST.COERCE ALLOC.TM Cast alters value Coercion alters v...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,226
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152226
3
13
API09-C
Compatible values should have the same type
Make sure compatible values have the same type. For example, when the return value of one function is used as an argument to another function, make sure they are the same type. Ensuring compatible values have the same type allows the return value to be passed as an argument to the related function without conversion, r...
ssize_t atomicio(f, fd, _s, n) ssize_t (*f) (int, void *, size_t); int fd; void *_s; size_t n; { char *s = _s; ssize_t res, pos = 0; while (n > pos) { res = (f) (fd, s + pos, n - pos); switch (res) { case -1: if (errno == EINTR || errno == EAGAIN) continue; case 0: ...
size_t atomicio(ssize_t (*f) (int, void *, size_t),  int fd, void *_s, size_t n) { char *s = _s; size_t pos = 0; ssize_t res; struct pollfd pfd; pfd.fd = fd; pfd.events = f == read ? POLLIN : POLLOUT; while (n > pos) { res = (f) (fd, s + pos, n - pos); switch (res) { case -1:...
## Risk Assessment The risk in using in-band error indicators is difficult to quantify and is consequently given as low. However, if the use of in-band error indicators results in programmers' failing to check status codes or incorrectly checking them, the consequences can be more severe. Recommendation Severity Likeli...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,151,961
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151961
3
13
API10-C
APIs should have security options enabled by default
APIS should have security options enabled by default– for example, having best practice cipher suites enabled by default (something that changes over time) while disabling out-of-favor cipher suites by default. When interface stability is also a design requirement, an interface can meet both goals by providing off-by-d...
int tls_connect_by_name(const char *host, int port, int option_bitmask); #define TLS_DEFAULT_OPTIONS 0 #define TLS_VALIDATE_HOST 0x0001 #define TLS_DISABLE_V1_0 0x0002 #define TLS_DISABLE_V1_1 0x0004 ## Noncompliant Code Example If the caller of this API in this noncompliant example doesn't understand what the options...
int tls_connect_by_name(const char *host, int port, int option_bitmask); #define TLS_DEFAULT_OPTIONS 0 #define TLS_DISABLE_HOST_VALIDATION 0x0001 // use rarely, subject to man-in-the-middle attack #define TLS_ENABLE_V1_0 0x0002 #define TLS_ENABLE_V1_1 0x0004 ## Compliant Solution If the caller of this API doesn't und...
## Risk Assessment Rule Severity Likelihood Detectable Repairable Priority Level API10-C Medium Likely No No P6 L3
SEI CERT C Coding Standard > 3 Recommendations > Rec. 13. Application Programming Interfaces (API)
c
87,152,117
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152117
3
6
ARR00-C
Understand how arrays work
The incorrect use of arrays has traditionally been a source of exploitable vulnerabilities . Elements referenced within an array using the subscript operator [] are not checked unless the programmer provides adequate bounds checking. As a result, the expression array [pos] = value can be used by an attacker to transfer...
null
null
## Risk Assessment Arrays are a common source of vulnerabilities in C language programs because they are frequently used but not always fully understood. Recommendation Severity Likelihood Detectable Repairable Priority Level ARR00-C High Probable No No P6 L2 Automated Detection Tool Version Checker Description LANG.CA...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 06. Arrays (ARR)
c
87,152,137
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152137
3
6
ARR01-C
Do not apply the sizeof operator to a pointer when taking the size of an array
The sizeof operator yields the size (in bytes) of its operand, which can be an expression or the parenthesized name of a type. However, using the sizeof operator to determine the size of arrays is error prone. The sizeof operator is often used in determining how much memory to allocate via malloc() . However using an i...
void clear(int array[]) { for (size_t i = 0; i < sizeof(array) / sizeof(array[0]); ++i) { array[i] = 0; } } void dowork(void) { int dis[12]; clear(dis); /* ... */ } enum {ARR_LEN = 100}; void clear(int a[ARR_LEN]) { memset(a, 0, sizeof(a)); /* Error */ } int main(void) { int b[ARR_LEN]; clear...
void clear(int array[], size_t len) { for (size_t i = 0; i < len; i++) { array[i] = 0; } } void dowork(void) { int dis[12]; clear(dis, sizeof(dis) / sizeof(dis[0])); /* ... */ } enum {ARR_LEN = 100}; void clear(int a[], size_t len) { memset(a, 0, len * sizeof(int)); } int main(void) { int b[ARR_L...
## Risk Assessment Incorrectly using the sizeof operator to determine the size of an array can result in a buffer overflow, allowing the execution of arbitrary code. Recommendation Severity Likelihood Detectable Repairable Priority Level ARR01-C High Probable No Yes P12 L1 Automated Detection Tool Version Checker Descr...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 06. Arrays (ARR)
c
87,152,105
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152105
3
6
ARR02-C
Explicitly specify array bounds, even if implicitly defined by an initializer
The C Standard allows an array variable to be declared both with a bound and with an initialization literal. The initialization literal also implies an array bound in the number of elements specified. The size implied by an initialization literal is usually specified by the number of elements, int array[] = {1, 2, 3}; ...
int a[3] = {1, 2, 3, 4}; int a[] = {1, 2, 3, 4}; ## Noncompliant Code Example (Incorrect Size) This noncompliant code example initializes an array of integers using an initialization with too many elements for the array: #FFCCCC c int a[3] = {1, 2, 3, 4}; The size of the array a is 3, although the size of the initial...
int a[4] = {1, 2, 3, 4}; ## Compliant Solution ## This compliant solution explicitly specifies the array bound: #ccccff c int a[4] = {1, 2, 3, 4}; Explicitly specifying the array bound, although it is implicitly defined by an initializer, allows a compiler or other static analysis tool to issue a diagnostic if these v...
## Risk Assessment Recommendation Severity Likelihood Detectable Repairable Priority Level ARR02-C Medium Unlikely Yes Yes P6 L2 Automated Detection Tool Version Checker Description array-size-global Partially checked CertC-ARR02 Fully implemented Compass/ROSE CC2.ARR02 Fully implemented C0678, C0688, C3674, C3684 LDRA...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 06. Arrays (ARR)
c
87,152,322
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152322
2
6
ARR30-C
Do not form or use out-of-bounds pointers or array subscripts
The C Standard identifies the following distinct situations in which undefined behavior (UB) can arise as a result of invalid pointer operations: UB Description Example Code 43 Addition or subtraction of a pointer into, or just beyond, an array object and an integer type produces a result that does not point into, or j...
enum { TABLESIZE = 100 }; static int table[TABLESIZE]; int *f(int index) { if (index < TABLESIZE) { return table + index; } return NULL; } error_status_t _RemoteActivation( /* ... */, WCHAR *pwszObjectName, ... ) { *phr = GetServerPath( pwszObjectName, &pwszObjectName); /* ... */...
enum { TABLESIZE = 100 }; static int table[TABLESIZE]; int *f(int index) { if (index >= 0 && index < TABLESIZE) { return table + index; } return NULL; } #include <stddef.h>   enum { TABLESIZE = 100 }; static int table[TABLESIZE]; int *f(size_t index) { if (index < TABLESIZE) { return table + index;...
## Risk Assessment Writing to out-of-range pointers or array subscripts can result in a buffer overflow and the execution of arbitrary code with the permissions of the vulnerable process. Reading from out-of-range pointers or array subscripts can result in unintended information disclosure. Rule Severity Likelihood Det...
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,152,385
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152385
2
6
ARR32-C
Ensure size arguments for variable length arrays are in a valid range
Variable length arrays (VLAs), a conditionally supported language feature, are essentially the same as traditional C arrays except that they are declared with a size that is not a constant integer expression and can be declared only at block scope or function prototype scope and no linkage. When supported, a variable l...
#include <stddef.h> extern void do_work(int *array, size_t size);   void func(size_t size) { int vla[size]; do_work(vla, size); } #include <stdlib.h> #include <string.h>   enum { N1 = 4096 }; void *func(size_t n2) { typedef int A[n2][N1]; A *array = malloc(sizeof(A)); if (!array) { /* Handle error */ ...
#include <stdint.h> #include <stdlib.h>   enum { MAX_ARRAY = 1024 }; extern void do_work(int *array, size_t size);   void func(size_t size) { if (0 == size || SIZE_MAX / sizeof(int) < size) { /* Handle error */ return; } if (size < MAX_ARRAY) { int vla[size]; do_work(vla, size); } else { int...
## Risk Assessment Failure to properly specify the size of a variable length array may allow arbitrary code execution or result in stack exhaustion. Rule Severity Likelihood Detectable Repairable Priority Level ARR32-C High Probable No No P6 L2 Automated Detection Tool Version Checker Description variable-array-length ...
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,152,341
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152341
2
6
ARR36-C
Do not subtract or compare two pointers that do not refer to the same array
When two pointers are subtracted, both must point to elements of the same array object or just one past the last element of the array object (C Standard, 6.5.7 [ ISO/IEC 9899:2024 ]); the result is the difference of the subscripts of the two array elements. Otherwise, the operation is undefined behavior . (See undefine...
#include <stddef.h>   enum { SIZE = 32 };   void func(void) { int nums[SIZE]; int end; int *next_num_ptr = nums; size_t free_elements; /* Increment next_num_ptr as array fills */ free_elements = &end - next_num_ptr; } ## Noncompliant Code Example In this noncompliant code example, pointer subtraction is ...
#include <stddef.h> enum { SIZE = 32 };   void func(void) { int nums[SIZE]; int *next_num_ptr = nums; size_t free_elements; /* Increment next_num_ptr as array fills */ free_elements = &(nums[SIZE]) - next_num_ptr; } ## Compliant Solution In this compliant solution, the number of free elements is computed b...
## Risk Assessment Rule Severity Likelihood Detectable Repairable Priority Level ARR36-C Medium Probable No No P4 L3 Automated Detection Tool Version Checker Description pointer-subtraction pointer-comparison Partially checked CertC-ARR36 Can detect operations on pointers that are unrelated LANG.STRUCT.CUP LANG.STRUCT....
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,152,085
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152085
2
6
ARR37-C
Do not add or subtract an integer to a pointer to a non-array object
Pointer arithmetic must be performed only on pointers that reference elements of array objects. The C Standard, 6.5.7 [ ISO/IEC 9899:2024 ], states the following about pointer arithmetic: When an expression that has integer type is added to or subtracted from a pointer, the result has the type of the pointer operand. I...
struct numbers { short num_a, num_b, num_c; }; int sum_numbers(const struct numbers *numb){ int total = 0; const short *numb_ptr; for (numb_ptr = &numb->num_a; numb_ptr <= &numb->num_c; numb_ptr++) { total += *(numb_ptr); } return total; } int main(void) { struct numbers my_numbers =...
total = numb->num_a + numb->num_b + numb->num_c; #include <stddef.h> struct numbers { short a[3]; }; int sum_numbers(const short *numb, size_t dim) { int total = 0; for (size_t i = 0; i < dim; ++i) { total += numb[i];  } return total; } int main(void) { struct numbers my_numbers = { .a[0]= 1, .a[1]=...
## Risk Assessment Rule Severity Likelihood Detectable Repairable Priority Level ARR37-C Medium Probable Yes No P8 L2 Automated Detection Tool Version Checker Description Supported indirectly via MISRA C:2004 Rule 17.4. CertC-ARR37 Fully implemented LANG.MEM.BO LANG.MEM.BU LANG.STRUCT.PARITH LANG.STRUCT.PBB LANG.STRUCT...
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,151,963
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151963
2
6
ARR38-C
Guarantee that library functions do not form invalid pointers
C library functions that make changes to arrays or objects take at least two arguments: a pointer to the array or object and an integer indicating the number of elements or bytes to be manipulated. For the purposes of this rule, the element count of a pointer is the size of the object to which it points, expressed by t...
null
#include <string.h>   void f2(void) { const size_t ARR_SIZE = 4; long a[ARR_SIZE]; const size_t n = sizeof(a); void *p = a; memset(p, 0, n); } #include <string.h> void f4() { char p[40]; const char *q = "Too short"; size_t n = sizeof(p) < strlen(q) + 1 ? sizeof(p) : strlen(q) + 1; memcpy(p, q, n); ...
null
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,152,330
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152330
2
6
ARR39-C
Do not add or subtract a scaled integer to a pointer
Pointer arithmetic is appropriate only when the pointer argument refers to an array (see ), including an array of bytes. When performing pointer arithmetic, the size of the value to add to or subtract from a pointer is automatically scaled to the size of the type of the referenced array object. Adding or subtracting a ...
enum { INTBUFSIZE = 80 }; extern int getdata(void); int buf[INTBUFSIZE];   void func(void) { int *buf_ptr = buf; while (buf_ptr < (buf + sizeof(buf))) { *buf_ptr++ = getdata(); } } #include <string.h> #include <stdlib.h> #include <stddef.h>   struct big { unsigned long long ull_a; unsigned long long ul...
enum { INTBUFSIZE = 80 }; extern int getdata(void); int buf[INTBUFSIZE]; void func(void) { int *buf_ptr = buf; while (buf_ptr < (buf + INTBUFSIZE)) { *buf_ptr++ = getdata(); } } #include <string.h> #include <stdlib.h> #include <stddef.h>   struct big { unsigned long long ull_a; unsigned long long ull_...
## Risk Assessment Failure to understand and properly use pointer arithmetic can allow an attacker to execute arbitrary code. Rule Severity Likelihood Detectable Repairable Priority Level ARR39-C High Probable No No P6 L2 Automated Detection Tool Version Checker Description scaled-pointer-arithmetic Partially checked B...
SEI CERT C Coding Standard > 2 Rules > Rule 06. Arrays (ARR)
c
87,152,303
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152303
3
14
CON01-C
Acquire and release synchronization primitives in the same module, at the same level of abstraction
All locking and unlocking of mutexes should be performed in the same module and at the same level of abstraction. Failure to follow this recommendation can lead to some lock or unlock operations not being executed by the multithreaded program as designed, eventually resulting in deadlock, race conditions, or other secu...
#include <threads.h> enum { MIN_BALANCE = 50 }; int account_balance; mtx_t mp; /* Initialize mp */ int verify_balance(int amount) { if (account_balance - amount < MIN_BALANCE) { /* Handle error condition */ if (mtx_unlock(&mp) == thrd_error) { /* Handle error */ } return -1; } return 0;...
#include <threads.h> enum { MIN_BALANCE = 50 }; static int account_balance; static mtx_t mp; /* Initialize mp */ static int verify_balance(int amount) { if (account_balance - amount < MIN_BALANCE) { return -1; /* Indicate error to caller */ }  return 0; /* Indicate success to caller */ } int debit(int...
## Risk Assessment Improper use of mutexes can result in denial-of-service attacks or the unexpected termination of a multithreaded program. Recommendation Severity Likelihood Detectable Repairable Priority Level CON01-C Low Probable Yes No P4 L3
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,152,314
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152314
3
14
CON02-C
Do not use volatile as a synchronization primitive
The C Standard, subclause 5.1.2.3, paragraph 2 [ ISO/IEC 9899:2011 ], says: Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression in genera...
bool flag = false; void test() { while (!flag) { sleep(1000); } } void wakeup(){ flag = true; } void debit(unsigned int amount){ test(); account_balance -= amount; } volatile bool flag = false; void test() { while (!flag){ sleep(1000); } } void wakeup(){ flag = true; } void debit(unsigned...
#include <threads.h> int account_balance; mtx_t flag; /* Initialize flag */ int debit(unsigned int amount) { if (mtx_lock(&flag) == thrd_error) { return -1; /* Indicate error */ }  account_balance -= amount; /* Inside critical section */  if (mtx_unlock(&flag) == thrd_error) { return -1; /* Indica...
## Risk Assessment Recommendation Severity Likelihood Detectable Repairable Priority Level CON02-C Medium Probable No No P4 L3
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,152,036
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152036
3
14
CON03-C
Ensure visibility when accessing shared variables
Reading a shared primitive variable in one thread may not yield the value of the most recent write to the variable from another thread. Consequently, the thread may observe a stale value of the shared variable. To ensure the visibility of the most recent update, the write to the variable must happen before the read (C ...
final class ControlledStop implements Runnable { private boolean done = false; @Override public void run() { while (!done) { try { // ... Thread.currentThread().sleep(1000); // Do something } catch(InterruptedException ie) { Thread.currentThread().interrupt(); // Reset int...
final class ControlledStop implements Runnable { private volatile boolean done = false; @Override public void run() { while (!done) { try { // ... Thread.currentThread().sleep(1000); // Do something } catch(InterruptedException ie) { Thread.currentThread().interrupt(); // ...
## Risk Assessment Rule Severity Likelihood Detectable Repairable Priority Level CON03-C Medium Probable No No P4 L3 Automated Detection Tool Version Checker Description Supported, but no explicit checker C1765 C1766
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,152,305
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152305
3
14
CON04-C
Join or detach threads even if their exit status is unimportant
The thrd_detach() function is used to tell the underlying system that resources allocated to a particular thread can be reclaimed once it terminates. This function should be used when a thread's exit status is not required by other threads (and no other thread needs to use thrd_join() to wait for it to complete). Whene...
#include <stdio.h> #include <threads.h>   const size_t thread_no = 5; const char mess[] = "This is a test"; int message_print(void *ptr){ const char *msg = (const char *) ptr; printf("THREAD: This is the Message %s\n", msg); return 0; } int main(void){ /* Create a pool of threads */ thrd_t thr[thread_no]; ...
#include <stdio.h> #include <threads.h>   const size_t thread_no = 5; const char mess[] = "This is a test"; int message_print(void *ptr){ const char *msg = (const char *)ptr; printf("THREAD: This is the Message %s\n", msg);   /* Detach the thread, check the return code for errors */ if (thrd_detach(thrd_curren...
## Risk Assessment Recommendation Severity Likelihood Detectable Repairable Priority Level CON04-C Low Unlikely Yes No P2 L3 Related Vulnerabilities Search for vulnerabilities resulting from the violation of this rule on the CERT website .
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,151,981
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151981
3
14
CON05-C
Do not perform operations that can block while holding a lock
If a lock is being held and an operation that can block is performed, any other thread that needs to acquire that lock may also block. This condition can degrade system performance or cause a deadlock to occur.  Blocking calls include, but are not limited to, network, file, and console I/O. Using a blocking operation w...
#include <stdio.h> #include <threads.h>   mtx_t mutex; int thread_foo(void *ptr) { int result; FILE *fp; if ((result = mtx_lock(&mutex)) != thrd_success) { /* Handle error */ }   fp = fopen("SomeNetworkFile", "r"); if (fp != NULL) { /* Work with the file */ fclose(fp); }   if ((result = mt...
#include <stdio.h> #include <threads.h>   mtx_t mutex;   int thread_foo(void *ptr) { int result; FILE *fp = fopen("SomeNetworkFile", "r");   if (fp != NULL) { /* Work with the file */ fclose(fp); } if ((result = mtx_lock(&mutex)) != thrd_success) { /* Handle error */ } /* ... */ if ((resu...
## Risk Assessment Blocking or lengthy operations performed within synchronized regions could result in a deadlocked or an unresponsive system. Recommendation Severity Likelihood Detectable Repairable Priority Level CON05-C Low Probable No No P2 L3 Automated Detection Tool Version Checker Description CONCURRENCY.STARVE...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,151,935
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151935
3
14
CON06-C
Ensure that every mutex outlives the data it protects
## ********** Text below this note not yet converted from Java to C! ************ Programs must not use instance locks to protect static shared data because instance locks are ineffective when two or more instances of the class are created. Consequently, failure to use a static lock object leaves the shared state unpro...
## Noncompliant Code Example (Nonstatic Lock Object for Static Data) This noncompliant code example attempts to guard access to the static counter field using a non-static lock object. When two Runnable tasks are started, they create two instances of the lock object and lock on each instance separately. public final cl...
## Compliant Solution (Static Lock Object) ## This compliant solution ensures the atomicity of the increment operation by locking on a static object. public class CountBoxes implements Runnable { private static int counter; // ... private static final Object lock = new Object(); public void run() { synchronized (lock) ...
## Risk Assessment Using an instance lock to protect static shared data can result in nondeterministic behavior. Rule Severity Likelihood Detectable Repairable Priority Level CON06-C Medium Probable No No P4 L3 Automated Detection Tool Version Checker Description Supported, but no explicit checker
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,151,920
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151920
3
14
CON07-C
Ensure that compound operations on shared variables are atomic
Compound operations are operations that consist of more than one discrete operation. Expressions that include postfix or prefix increment ( ++ ), postfix or prefix decrement ( -- ), or compound assignment operators always result in compound operations. Compound assignment expressions use operators such as *= , /= , %= ...
null
null
null
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,151,947
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151947
3
14
CON08-C
Do not assume that a group of calls to independently atomic methods is atomic
A consistent locking policy guarantees that multiple threads cannot simultaneously access or modify shared data. When two or more operations must be performed as a single atomic operation, a consistent locking policy must be implemented using some form of locking, such as a mutex. In the absence of such a policy, the c...
null
null
null
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,151,982
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87151982
3
14
CON09-C
Avoid the ABA problem when using lock-free algorithms
Lock-free programming is a technique that allows concurrent updates of shared data structures without using explicit locks. This method ensures that no threads block for arbitrarily long times, and it thereby boosts performance. Lock-free programming has the following advantages: Can be used in places where locks must ...
#include <stdatomic.h>   /* * Sets index to point to index of maximum element in array * and value to contain maximum array value.  */ void find_max_element(atomic_int array[], size_t *index, int *value); static atomic_int array[]; void func(void) { size_t index; int value; find_max_element(array, &index, &va...
#include <stdatomic.h> #include <threads.h>   static atomic_int array[]; static mtx_t array_mutex; void func(void) { size_t index; int value; if (thrd_success != mtx_lock(&array_mutex)) { /* Handle error */ } find_max_element(array, &index, &value); /* ... */ if (!atomic_compare_exchange_strong(array...
## Risk Assessment The likelihood of having a race condition is low. Once the race condition occurs, the reading memory that has already been freed can lead to abnormal program termination or unintended information disclosure. Recommendation Severity Likelihood Detectable Repairable Priority Level CON09-C Medium Unlike...
SEI CERT C Coding Standard > 3 Recommendations > Rec. 14. Concurrency (CON)
c
87,152,258
https://wiki.sei.cmu.edu/confluence/pages/viewpage.action?pageId=87152258
2
14
CON30-C
Clean up thread-specific storage
The tss_create() function creates a thread-specific storage pointer identified by a key. Threads can allocate thread-specific storage and associate the storage with a key that uniquely identifies the storage by calling the tss_set() function. If not properly freed, this memory may be leaked. Ensure that thread-specific...
#include <threads.h> #include <stdlib.h> /* Global key to the thread-specific storage */ tss_t key; enum { MAX_THREADS = 3 }; int *get_data(void) { int *arr = (int *)malloc(2 * sizeof(int)); if (arr == NULL) { return arr; /* Report error */ } arr[0] = 10; arr[1] = 42; return arr; } int add_data(voi...
#include <threads.h> #include <stdlib.h> /* Global key to the thread-specific storage */ tss_t key; int function(void *dummy) { if (add_data() != 0) { return -1; /* Report error */ } print_data(); free(tss_get(key)); return 0; } /* ... Other functions are unchanged */ #include <threads.h> #include <...
## Risk Assessment Failing to free thread-specific objects results in memory leaks and could result in a denial-of-service attack . Rule Severity Likelihood Detectable Repairable Priority Level CON30-C Medium Unlikely No No P2 L3
SEI CERT C Coding Standard > 2 Rules > Rule 14. Concurrency (CON)
End of preview. Expand in Data Studio

Dataset Card for SEI CERT C Coding Standard (Wiki rules)

Structured export of the SEI CERT C Coding Standard rules from the official SEI wiki: one row per rule with titles, prose, and code examples.

Dataset Details

Dataset Description

This dataset is a tabular snapshot of CERT C secure coding guidance as published on the SEI Confluence wiki. It is intended for retrieval, training data for code assistants, lint-rule authoring, and security education—not as a substitute for the authoritative standard.

  • Curated by: Derived from public SEI CERT wiki pages; packaged as CSV by the dataset maintainer.
  • Funded by [optional]: [More Information Needed]
  • Shared by [optional]: [More Information Needed]
  • Language(s) (NLP): English (rule text and embedded code).
  • License: Compilation distributed as other; source material is the publicly published SEI CERT standard on the CMU SEI wiki. Verify licensing for your use case with CMU SEI / the wiki terms.

Dataset Sources [optional]

Uses

Direct Use

Secure coding education, semantic search over rules, benchmarking static analyzers, and supervised fine-tuning for security-focused models.

Out-of-Scope Use

Not a legal or compliance certification. Do not treat scraped wiki text as legally binding; always consult the current official standard and your policies.

Dataset Structure

All rows share the same columns (scraped from the SEI CERT Confluence wiki):

Column Description
language Language identifier for the rule set
page_id Confluence page id
page_url Canonical wiki URL for the rule page
chapter Chapter label when present
section Section label when present
rule_id Rule identifier (e.g. API00-C, CON50-J)
title Short rule title
intro Normative / explanatory text
noncompliant_code Noncompliant example(s) when present
compliant_solution Compliant example(s) when present
risk_assessment Risk / severity notes when present
breadcrumb Wiki breadcrumb trail when present

Dataset Creation

Curation Rationale

Machine-readable rule text lowers the barrier to tooling and research aligned with CERT guidance.

Source Data

Data Collection and Processing

Pages were scraped from the SEI wiki; fields were normalized into CSV columns. See the companion scrape_sei_wiki.py in the source project if applicable.

Who are the source data producers?

[More Information Needed]

Annotations [optional]

Annotation process

[More Information Needed]

Who are the annotators?

[More Information Needed]

Personal and Sensitive Information

[More Information Needed]

Bias, Risks, and Limitations

[More Information Needed]

Recommendations

Users should be made aware of the risks, biases and limitations of the dataset. More information needed for further recommendations.

Citation [optional]

BibTeX:

[More Information Needed]

APA:

[More Information Needed]

Glossary [optional]

[More Information Needed]

More Information [optional]

[More Information Needed]

Dataset Card Authors [optional]

[More Information Needed]

Dataset Card Contact

[More Information Needed]

Downloads last month
41