Skip to content

Commit 5928bcc

Browse files
author
Nikita Kraiouchkine
committed
Define InvalidMemory2 and Memory3 packages
1 parent 9822ec6 commit 5928bcc

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
"Macros",
243243
"Memory1",
244244
"Memory2",
245+
"Memory3",
245246
"Misc",
246247
"MoveForward",
247248
"Naming",

rule_packages/c/InvalidMemory2.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"CERT-C": {
3+
"ARR32-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "A variable-length array size that is zero, negative, overflowed, wrapped around, or excessively large may lead to undefined behaviour.",
10+
"kind": "problem",
11+
"name": "Ensure size arguments for variable length arrays are in a valid range",
12+
"precision": "high",
13+
"severity": "error",
14+
"short_name": "VariableLengthArraySizeNotInValidRange",
15+
"tags": [
16+
"correctness",
17+
"security"
18+
]
19+
}
20+
],
21+
"title": "Ensure size arguments for variable length arrays are in a valid range"
22+
},
23+
"ARR37-C": {
24+
"properties": {
25+
"obligation": "rule"
26+
},
27+
"queries": [
28+
{
29+
"description": "A pair of elements that are not elements in the same array are not guaranteed to be contiguous in memory and therefore should not be addressed using pointer arithmetic.",
30+
"kind": "path-problem",
31+
"name": "Do not add or subtract an integer to a pointer to a non-array object",
32+
"precision": "high",
33+
"severity": "error",
34+
"short_name": "DoNotUsePointerArithmeticOnNonArrayObjectPointers",
35+
"tags": [
36+
"correctness"
37+
]
38+
}
39+
],
40+
"title": "Do not add or subtract an integer to a pointer to a non-array object"
41+
},
42+
"EXP35-C": {
43+
"properties": {
44+
"obligation": "rule"
45+
},
46+
"queries": [
47+
{
48+
"description": "Attempting to modify an object with temporary lifetime results in undefined behavior.",
49+
"kind": "problem",
50+
"name": "Do not modify objects with temporary lifetime",
51+
"precision": "high",
52+
"severity": "error",
53+
"short_name": "DoNotModifyObjectsWithTemporaryLifetime",
54+
"tags": [
55+
"correctness"
56+
],
57+
"implementation_scope": {
58+
"description": "This implementation also always reports non-modifying accesses of objects with temporary lifetime, which are only compliant in C11."
59+
}
60+
}
61+
],
62+
"title": "Do not modify objects with temporary lifetime"
63+
}
64+
}
65+
}

rule_packages/c/Memory3.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"CERT-C": {
3+
"MEM35-C": {
4+
"properties": {
5+
"obligation": "rule"
6+
},
7+
"queries": [
8+
{
9+
"description": "The size of memory allocated dynamically must be adequate to represent the type of object referenced by the allocated memory.",
10+
"kind": "problem",
11+
"name": "Allocate sufficient memory for an object",
12+
"precision": "medium",
13+
"severity": "error",
14+
"short_name": "InsufficientMemoryAllocatedForObject",
15+
"tags": [
16+
"correctness",
17+
"security"
18+
]
19+
}
20+
],
21+
"title": "Allocate sufficient memory for an object"
22+
}
23+
}
24+
}

rules.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ cpp,CERT-C++,STR50-CPP,Yes,Rule,,,Guarantee that storage for strings has suffici
479479
cpp,CERT-C++,STR51-CPP,Yes,Rule,,,Do not attempt to create a std::string from a null pointer,,Null,Hard,
480480
cpp,CERT-C++,STR52-CPP,Yes,Rule,,,"Use valid references, pointers, and iterators to reference elements of a basic_string",,Iterators,Hard,
481481
cpp,CERT-C++,STR53-CPP,Yes,Rule,,,Range check element access,,OutOfBounds,Hard,
482-
c,CERT-C,ARR30-C,Yes,Rule,,,Do not form or use out-of-bounds pointers or array subscripts,,InvalidMemory2,Medium,
482+
c,CERT-C,ARR30-C,Yes,Rule,,,Do not form or use out-of-bounds pointers or array subscripts,,OutOfBounds,Hard,
483483
c,CERT-C,ARR32-C,Yes,Rule,,,Ensure size arguments for variable length arrays are in a valid range,,InvalidMemory2,Medium,
484484
c,CERT-C,ARR36-C,Yes,Rule,,,Do not subtract or compare two pointers that do not refer to the same array,,Memory2,Medium,
485485
c,CERT-C,ARR37-C,Yes,Rule,,,Do not add or subtract an integer to a pointer to a non-array object,,InvalidMemory2,Medium,
@@ -559,7 +559,7 @@ c,CERT-C,MEM30-C,Yes,Rule,,,Do not access freed memory,MEM50-CPP,InvalidMemory1,
559559
c,CERT-C,MEM31-C,Yes,Rule,,,Free dynamically allocated memory when no longer needed,,Memory2,Very Hard,
560560
c,CERT-C,MEM33-C,Yes,Rule,,,Allocate and copy structures containing a flexible array member dynamically,,Memory2,Very Hard,
561561
c,CERT-C,MEM34-C,Yes,Rule,,,Only free memory allocated dynamically,,Memory2,Hard,
562-
c,CERT-C,MEM35-C,Yes,Rule,,,Allocate sufficient memory for an object,,Memory2,Very Hard,
562+
c,CERT-C,MEM35-C,Yes,Rule,,,Allocate sufficient memory for an object,,Memory3,Very Hard,
563563
c,CERT-C,MEM36-C,Yes,Rule,,,Do not modify the alignment of objects by calling realloc(),,Memory2,Medium,
564564
c,CERT-C,MSC30-C,Yes,Rule,,,Do not use the rand() function for generating pseudorandom numbers,MSC50-CPP,Misc,Easy,
565565
c,CERT-C,MSC32-C,Yes,Rule,,,Properly seed pseudorandom number generators,MSC51-CPP,Misc,Easy,
@@ -664,7 +664,7 @@ c,MISRA-C-2012,RULE-9-1,Yes,Mandatory,,,The value of an object with automatic st
664664
c,MISRA-C-2012,RULE-9-2,Yes,Required,,,The initializer for an aggregate or union shall be enclosed in braces,,Memory1,Easy,
665665
c,MISRA-C-2012,RULE-9-3,Yes,Required,,,Arrays shall not be partially initialized,,Memory1,Medium,
666666
c,MISRA-C-2012,RULE-9-4,Yes,Required,,,An element of an object shall not be initialized more than once,,Memory1,Medium,
667-
c,MISRA-C-2012,RULE-9-5,Yes,Required,,,Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly,,Memory2,Medium,
667+
c,MISRA-C-2012,RULE-9-5,No,Required,,,Where designated initializers are used to initialize an array object the size of the array shall be specified explicitly,,,Medium,
668668
c,MISRA-C-2012,RULE-10-1,Yes,Required,,,Operands shall not be of an inappropriate essential type,,EssentialTypes,Hard,
669669
c,MISRA-C-2012,RULE-10-2,Yes,Required,,,Expressions of essentially character type shall not be used inappropriately in addition and subtraction operations,,EssentialTypes,Medium,
670670
c,MISRA-C-2012,RULE-10-3,Yes,Required,,,The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category,,EssentialTypes,Hard,
@@ -759,7 +759,7 @@ c,MISRA-C-2012,RULE-21-13,Yes,Mandatory,,,Any value passed to a function in <cty
759759
c,MISRA-C-2012,RULE-21-14,Yes,Required,,,The Standard Library function memcmp shall not be used to compare null terminated strings,,EssentialTypes,Hard,
760760
c,MISRA-C-2012,RULE-21-15,Yes,Required,,,"The pointer arguments to the Standard Library functions memcpy, memmove and memcmp shall be pointers to qualified or unqualified versions of compatible types",,StandardLibraryFunctionTypes,Medium,
761761
c,MISRA-C-2012,RULE-21-16,Yes,Required,,,"The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type",,EssentialTypes,Medium,
762-
c,MISRA-C-2012,RULE-21-17,Yes,Mandatory,,,Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters,,Memory2,Hard,
762+
c,MISRA-C-2012,RULE-21-17,Yes,Mandatory,,,Use of the string handling functions from <string.h> shall not result in accesses beyond the bounds of the objects referenced by their pointer parameters,,OutOfBounds,Hard,
763763
c,MISRA-C-2012,RULE-21-18,Yes,Mandatory,,,The size_t argument passed to any function in <string.h> shall have an appropriate value,,OutOfBounds,Hard,
764764
c,MISRA-C-2012,RULE-21-19,Yes,Mandatory,,,"The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type",ENV30-C,Contracts2,Medium,
765765
c,MISRA-C-2012,RULE-21-20,Yes,Mandatory,,,"The pointer returned by the Standard Library functions asctime, ctime, gmtime, localtime, localeconv, getenv, setlocale or strerror shall not be used following a subsequent call to the same function",ENV34-C,Contracts2,Import,

0 commit comments

Comments
 (0)