Skip to content

Commit d0e0471

Browse files
committed
C++: add remote flow models for fread and gets
1 parent a006bd3 commit d0e0471

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import semmle.code.cpp.models.interfaces.Alias
2+
import semmle.code.cpp.models.interfaces.FlowSource
23

3-
class Fread extends AliasFunction {
4+
class Fread extends AliasFunction, RemoteFlowFunction {
45
Fread() { this.hasGlobalName("fread") }
56

67
override predicate parameterNeverEscapes(int n) {
@@ -11,4 +12,8 @@ class Fread extends AliasFunction {
1112
override predicate parameterEscapesOnlyViaReturn(int n) { none() }
1213

1314
override predicate parameterIsAlwaysReturned(int n) { none() }
15+
16+
override predicate hasFlowSource(FunctionOutput output) {
17+
output.isParameterDeref(0)
18+
}
1419
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import semmle.code.cpp.models.interfaces.Taint
33
import semmle.code.cpp.models.interfaces.ArrayFunction
44
import semmle.code.cpp.models.interfaces.Alias
55
import semmle.code.cpp.models.interfaces.SideEffect
6+
import semmle.code.cpp.models.interfaces.FlowSource
67

78
/**
89
* The standard functions `gets` and `fgets`.
910
*/
1011
class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunction, AliasFunction,
11-
SideEffectFunction {
12+
SideEffectFunction, RemoteFlowFunction {
1213
GetsFunction() {
1314
exists(string name | hasGlobalOrStdName(name) |
1415
name = "gets" or // gets(str)
@@ -42,4 +43,8 @@ class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunction, Alias
4243
buffer = true and
4344
mustWrite = true
4445
}
46+
47+
override predicate hasFlowSource(FunctionOutput output) {
48+
output.isParameterDeref(0)
49+
}
4550
}

0 commit comments

Comments
 (0)