Skip to content

Commit bca1be0

Browse files
authored
Merge pull request github#2135 from zlaski-semmle/zlaski/memset-model
[zlaski/memset-model] Add side effect modeling to Memset.
2 parents 25130f2 + fcc1938 commit bca1be0

File tree

1 file changed

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

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import semmle.code.cpp.Function
22
import semmle.code.cpp.models.interfaces.ArrayFunction
33
import semmle.code.cpp.models.interfaces.DataFlow
44
import semmle.code.cpp.models.interfaces.Alias
5+
import semmle.code.cpp.models.interfaces.SideEffect
56

67
/**
78
* The standard function `memset` and its assorted variants
89
*/
9-
class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction {
10+
class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction, SideEffectFunction {
1011
MemsetFunction() {
1112
hasGlobalName("memset") or
1213
hasGlobalName("wmemset") or
@@ -38,4 +39,17 @@ class MemsetFunction extends ArrayFunction, DataFlowFunction, AliasFunction {
3839
override predicate parameterIsAlwaysReturned(int index) {
3940
not hasGlobalName("bzero") and index = 0
4041
}
42+
43+
override predicate hasOnlySpecificReadSideEffects() { any() }
44+
45+
override predicate hasOnlySpecificWriteSideEffects() { any() }
46+
47+
override predicate hasSpecificWriteSideEffect(ParameterIndex i, boolean buffer, boolean mustWrite) {
48+
i = 0 and buffer = true and mustWrite = true
49+
}
50+
51+
override ParameterIndex getParameterSizeIndex(ParameterIndex i) {
52+
i = 0 and
53+
if hasGlobalName("bzero") then result = 1 else result = 2
54+
}
4155
}

0 commit comments

Comments
 (0)