Skip to content

Commit 27b41c2

Browse files
committed
C++: Address review comments.
1 parent c747914 commit 27b41c2

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

  • cpp/ql/src/semmle/code/cpp/models/implementations

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import semmle.code.cpp.models.interfaces.SideEffect
1515
private class Sscanf extends ArrayFunction, TaintFunction, AliasFunction, SideEffectFunction {
1616
Sscanf() {
1717
this.hasGlobalOrStdName([
18-
"sscanf", // sscanf(src_stream, format, args...)
18+
"sscanf", // sscanf(src, format, args...)
1919
"swscanf", // swscanf(src, format, args...)
2020
"fscanf", // fscanf(src_stream, format, args...)
2121
"fwscanf" // fwscanf(src_stream, format, args...)
@@ -32,11 +32,16 @@ private class Sscanf extends ArrayFunction, TaintFunction, AliasFunction, SideEf
3232
])
3333
}
3434

35+
private predicate isSscanf() { this.getName().regexpMatch(".*sn?w?scanf.*") }
36+
3537
override predicate hasArrayWithNullTerminator(int bufParam) {
36-
bufParam = [0, getFormatPosition()]
38+
bufParam = getFormatPosition()
39+
or
40+
isSscanf() and
41+
bufParam = 0
3742
}
3843

39-
override predicate hasArrayInput(int bufParam) { bufParam = [0, getFormatPosition()] }
44+
override predicate hasArrayInput(int bufParam) { hasArrayWithNullTerminator(bufParam) }
4045

4146
private int getLengthPosition() {
4247
this.getName().matches("\\_sn%") and

0 commit comments

Comments
 (0)