Skip to content

Commit a62e2e1

Browse files
committed
Add supplementary query files
1 parent e9f39a2 commit a62e2e1

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

cpp/common/src/codingstandards/cpp/exclusions/cpp/Memory1.qll

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import cpp
33
import RuleMetadata
44
import codingstandards.cpp.exclusions.RuleMetadata
55

6-
newtype Memory1Query = TPointerArithmeticFormsAnInvalidPointerQuery()
6+
newtype Memory1Query =
7+
TPointerArithmeticFormsAnInvalidPointerQuery() or
8+
TPointerArgumentToCstringFunctionIsInvalidQuery()
79

810
predicate isMemory1QueryMetadata(Query query, string queryId, string ruleId, string category) {
911
query =
@@ -14,6 +16,15 @@ predicate isMemory1QueryMetadata(Query query, string queryId, string ruleId, str
1416
"cpp/misra/pointer-arithmetic-forms-an-invalid-pointer" and
1517
ruleId = "RULE-8-7-1" and
1618
category = "required"
19+
or
20+
query =
21+
// `Query` instance for the `pointerArgumentToCstringFunctionIsInvalid` query
22+
Memory1Package::pointerArgumentToCstringFunctionIsInvalidQuery() and
23+
queryId =
24+
// `@id` for the `pointerArgumentToCstringFunctionIsInvalid` query
25+
"cpp/misra/pointer-argument-to-cstring-function-is-invalid" and
26+
ruleId = "RULE-8-7-1" and
27+
category = "required"
1728
}
1829

1930
module Memory1Package {
@@ -23,4 +34,11 @@ module Memory1Package {
2334
// `Query` type for `pointerArithmeticFormsAnInvalidPointer` query
2435
TQueryCPP(TMemory1PackageQuery(TPointerArithmeticFormsAnInvalidPointerQuery()))
2536
}
37+
38+
Query pointerArgumentToCstringFunctionIsInvalidQuery() {
39+
//autogenerate `Query` type
40+
result =
41+
// `Query` type for `pointerArgumentToCstringFunctionIsInvalid` query
42+
TQueryCPP(TMemory1PackageQuery(TPointerArgumentToCstringFunctionIsInvalidQuery()))
43+
}
2644
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @id cpp/misra/pointer-argument-to-cstring-function-is-invalid
3+
* @name RULE-8-7-1: Pointer and index arguments passed to functions in <cstring> shall not be invalid.
4+
* @description Pointer and index arguments passed to functions in <cstring> should result in valid
5+
* reads and/or writes.
6+
* @kind problem
7+
* @precision high
8+
* @problem.severity error
9+
* @tags external/misra/id/rule-8-7-1
10+
* scope/system
11+
* external/misra/enforcement/undecidable
12+
* external/misra/obligation/required
13+
*/
14+
15+
import cpp
16+
import codingstandards.c.cert
17+
import codingstandards.c.OutOfBounds
18+
19+
from
20+
OOB::BufferAccessLibraryFunctionCall fc, string message, Expr bufferArg, string bufferArgStr,
21+
Expr sizeOrOtherBufferArg, string otherStr
22+
where
23+
not isExcluded(fc, OutOfBoundsPackage::libraryFunctionArgumentOutOfBoundsQuery()) and
24+
OOB::problems(fc, message, bufferArg, bufferArgStr, sizeOrOtherBufferArg, otherStr)
25+
select fc, message, bufferArg, bufferArgStr, sizeOrOtherBufferArg, otherStr
26+

cpp/misra/src/rules/RULE-8-7-1/PointerArithmeticFormsAnInvalidPointer.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @name RULE-8-7-1: Pointer arithmetic shall not form an invalid pointer.
44
* @description Pointers obtained as result of performing arithmetic should point to an initialized
55
* object, or an element right next to the last element of an array.
6-
* @kind path-problem
7-
* @precision very-high
6+
* @kind problem
7+
* @precision high
88
* @problem.severity error
99
* @tags external/misra/id/rule-8-7-1
1010
* scope/system
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No expected results have yet been specified
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rules/RULE-8-7-1/PointerArgumentToCstringFunctionIsInvalid.ql

0 commit comments

Comments
 (0)