Skip to content

Commit 144aacb

Browse files
committed
[zlaski/memset-model] New Memset.qll file.
1 parent ad8ae35 commit 144aacb

File tree

1 file changed

+28
-0
lines changed
  • cpp/ql/src/semmle/code/cpp/models/implementations

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import semmle.code.cpp.Function
2+
import semmle.code.cpp.models.interfaces.ArrayFunction
3+
import semmle.code.cpp.models.interfaces.DataFlow
4+
import semmle.code.cpp.models.interfaces.Taint
5+
6+
/**
7+
* The standard function `memset` and its assorted variants
8+
*/
9+
class MemsetFunction extends ArrayFunction, DataFlowFunction, TaintFunction {
10+
MemsetFunction() {
11+
hasGlobalName("memset") or
12+
hasGlobalName("bzero") or
13+
hasGlobalName("__builtin_memset") or
14+
hasQualifiedName("std", "memset")
15+
}
16+
17+
override predicate hasArrayOutput(int bufParam) { bufParam = 0 }
18+
19+
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
20+
input.isInParameter(0) and
21+
output.isOutReturnValue()
22+
}
23+
24+
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {
25+
bufParam = 0 and
26+
(if hasGlobalName("bzero") then countParam = 1 else countParam = 2)
27+
}
28+
}

0 commit comments

Comments
 (0)