Skip to content

Commit a006bd3

Browse files
committed
C++: add model-based RemoteFlowSource
1 parent 7c5c9ea commit a006bd3

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Provides a class for modeling functions that return data from potentially untrusted sources. To use
3+
* this QL library, create a QL class extending `DataFlowFunction` with a
4+
* characteristic predicate that selects the function or set of functions you
5+
* are modeling. Within that class, override the predicates provided by
6+
* `RemoteFlowFunction` to match the flow within that function.
7+
*/
8+
9+
import cpp
10+
import FunctionInputsAndOutputs
11+
import semmle.code.cpp.models.Models
12+
13+
/**
14+
* A library function which returns data read from a network connection.
15+
*/
16+
abstract class RemoteFlowFunction extends Function {
17+
abstract predicate hasFlowSource(FunctionOutput output);
18+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Provides classes representing various flow sources for taint tracking.
3+
*/
4+
5+
import cpp
6+
import semmle.code.cpp.ir.dataflow.DataFlow
7+
private import semmle.code.cpp.ir.IR
8+
import semmle.code.cpp.models.interfaces.FlowSource
9+
10+
/** A data flow source of remote user input. */
11+
abstract class RemoteFlowSource extends DataFlow::Node {
12+
}
13+
14+
class FileDescriptorTaintedReturnSource extends RemoteFlowSource {
15+
FileDescriptorTaintedReturnSource() {
16+
exists(RemoteFlowFunction func, CallInstruction instr, FunctionOutput output |
17+
asInstruction() = instr and
18+
instr.getStaticCallTarget() = func and
19+
func.hasFlowSource(output) and
20+
output.isReturnValue()
21+
)
22+
}
23+
}
24+
25+
class FileTaintedParameterSource extends RemoteFlowSource {
26+
FileTaintedParameterSource() {
27+
exists(RemoteFlowFunction func, ReadSideEffectInstruction instr, FunctionOutput output |
28+
asInstruction() = instr and
29+
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
30+
func.hasFlowSource(output) and
31+
output.isParameterDeref(instr.getIndex())
32+
)
33+
}
34+
}
35+

0 commit comments

Comments
 (0)