forked from github/codeql-coding-standards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacementNewInsufficientStorage.qll
More file actions
29 lines (25 loc) · 1.15 KB
/
PlacementNewInsufficientStorage.qll
File metadata and controls
29 lines (25 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Provides a library which includes a `problems` predicate for reporting calls to placement new
* expressions with insufficient storage.
*/
import cpp
import codingstandards.cpp.Customizations
import codingstandards.cpp.Exclusions
import codingstandards.cpp.allocations.PlacementNew
import PlacementNewOriginFlow::PathGraph
abstract class PlacementNewInsufficientStorageSharedQuery extends Query { }
Query getQuery() { result instanceof PlacementNewInsufficientStorageSharedQuery }
query predicate problems(
PlacementNewExpr placementNew, PlacementNewOriginFlow::PathNode source,
PlacementNewOriginFlow::PathNode sink, string message, PlacementNewMemoryOrigin memoryOrigin,
string memoryOriginDescription
) {
not isExcluded(placementNew, getQuery()) and
message =
"Placement new expression is used with an insufficiently large memory allocation from $@." and
memoryOrigin = source.getNode() and
placementNew.getPlacementExpr() = sink.getNode().asExpr() and
memoryOriginDescription = memoryOrigin.toString() and
PlacementNewOriginFlow::flowPath(source, sink) and
memoryOrigin.getMaximumMemorySize() < placementNew.getMinimumAllocationSize()
}