Skip to content

Commit ae169e9

Browse files
committed
[zlaski/memset-model] Add AliasFunction as base class of MemsetFunction; override predicates parameterNeverEscapes, parameterEscapesOnlyViaReturn and parameterIsAlwaysReturned.
1 parent aaa2a60 commit ae169e9

File tree

1 file changed

+14
-1
lines changed
  • cpp/ql/src/semmle/code/cpp/models/implementations

1 file changed

+14
-1
lines changed

cpp/ql/src/semmle/code/cpp/models/implementations/Memset.qll

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import semmle.code.cpp.Function
22
import semmle.code.cpp.models.interfaces.ArrayFunction
33
import semmle.code.cpp.models.interfaces.DataFlow
4+
import semmle.code.cpp.models.interfaces.Alias
45

56
/**
67
* The standard function `memset` and its assorted variants
78
*/
8-
class MemsetFunction extends ArrayFunction, DataFlowFunction {
9+
class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction {
910
MemsetFunction() {
1011
hasGlobalName("memset") or
1112
hasGlobalName("wmemset") or
@@ -27,4 +28,16 @@ class MemsetFunction extends ArrayFunction, DataFlowFunction {
2728
bufParam = 0 and
2829
(if hasGlobalName("bzero") then countParam = 1 else countParam = 2)
2930
}
31+
32+
override predicate parameterNeverEscapes(int index) {
33+
hasGlobalName("bzero") and index = 0
34+
}
35+
36+
override predicate parameterEscapesOnlyViaReturn(int index) {
37+
not hasGlobalName("bzero") and index = 0
38+
}
39+
40+
override predicate parameterIsAlwaysReturned(int index) {
41+
not hasGlobalName("bzero") and index = 0
42+
}
3043
}

0 commit comments

Comments
 (0)