Skip to content

Commit 70c7c1a

Browse files
committed
C++: Add flow from the fill character to the output pointer.
1 parent 8635b5d commit 70c7c1a

File tree

1 file changed

+17
-0
lines changed
  • cpp/ql/lib/semmle/code/cpp/models/implementations

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@ private class MemsetFunctionModel extends ArrayFunction, DataFlowFunction, Alias
2222
])
2323
}
2424

25+
/**
26+
* Gets the index of the parameter that specifies the fill character to insert, if any.
27+
*/
28+
private int getFillCharParameterIndex() {
29+
(
30+
this.hasGlobalOrStdOrBslName("memset")
31+
or
32+
this.hasGlobalOrStdName("wmemset")
33+
or
34+
this.hasGlobalName(["__builtin_memset", "__builtin_memset_chk"])
35+
) and
36+
result = 1
37+
}
38+
2539
override predicate hasArrayOutput(int bufParam) { bufParam = 0 }
2640

2741
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
2842
input.isParameter(0) and
2943
output.isReturnValue()
44+
or
45+
input.isParameter(this.getFillCharParameterIndex()) and
46+
(output.isParameterDeref(0) or output.isReturnValueDeref())
3047
}
3148

3249
override predicate hasArrayWithVariableSize(int bufParam, int countParam) {

0 commit comments

Comments
 (0)