Skip to content

Commit 0db54e0

Browse files
committed
C++: Address review comments.
1 parent be9908d commit 0db54e0

File tree

1 file changed

+4
-9
lines changed
  • cpp/ql/src/semmle/code/cpp/models/implementations

1 file changed

+4
-9
lines changed

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ private class SscanfModel extends ArrayFunction, TaintFunction, AliasFunction, S
1919
override predicate hasArrayWithNullTerminator(int bufParam) {
2020
bufParam = this.(ScanfFunction).getFormatParameterIndex()
2121
or
22-
bufParam = this.(Sscanf).getInputParameterIndex()
22+
not this instanceof Fscanf and
23+
bufParam = this.(ScanfFunction).getInputParameterIndex()
2324
}
2425

2526
override predicate hasArrayInput(int bufParam) { hasArrayWithNullTerminator(bufParam) }
@@ -35,16 +36,10 @@ private class SscanfModel extends ArrayFunction, TaintFunction, AliasFunction, S
3536
)
3637
}
3738

38-
private int getArgsStartPosition() {
39-
exists(int nLength, int nLocale |
40-
(if exists(getLocaleParameterIndex()) then nLocale = 1 else nLocale = 0) and
41-
(if exists(getLengthParameterIndex()) then nLength = 1 else nLength = 0) and
42-
result = 2 + nLocale + nLength
43-
)
44-
}
39+
private int getArgsStartPosition() { result = this.getNumberOfParameters() }
4540

4641
override predicate hasTaintFlow(FunctionInput input, FunctionOutput output) {
47-
input.isParameterDeref(0) and
42+
input.isParameterDeref(this.(ScanfFunction).getInputParameterIndex()) and
4843
output.isParameterDeref(any(int i | i >= getArgsStartPosition()))
4944
}
5045

0 commit comments

Comments
 (0)