Skip to content

Commit d0bb5ad

Browse files
committed
C++: rename and add description to hasFlowSource
1 parent e6630a8 commit d0bb5ad

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ class Fread extends AliasFunction, RemoteFlowFunction {
1313

1414
override predicate parameterIsAlwaysReturned(int n) { none() }
1515

16-
override predicate hasFlowSource(FunctionOutput output) {
17-
output.isParameterDeref(0)
16+
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
17+
output.isParameterDeref(0) and
18+
description = "String read by " + this.getName()
1819
}
1920
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class GetsFunction extends DataFlowFunction, TaintFunction, ArrayFunction, Alias
4444
mustWrite = true
4545
}
4646

47-
override predicate hasFlowSource(FunctionOutput output) {
48-
output.isParameterDeref(0)
47+
override predicate hasRemoteFlowSource(FunctionOutput output, string description) {
48+
output.isParameterDeref(0) and
49+
description = "String read by " + this.getName()
4950
}
5051
}

cpp/ql/src/semmle/code/cpp/models/interfaces/FlowSource.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ import semmle.code.cpp.models.Models
1414
* A library function which returns data read from a network connection.
1515
*/
1616
abstract class RemoteFlowFunction extends Function {
17-
abstract predicate hasFlowSource(FunctionOutput output);
17+
/**
18+
* Holds if remote data described by `description` flows from `output` of a call to this function.
19+
*/
20+
abstract predicate hasRemoteFlowSource(FunctionOutput output, string description);
1821
}

cpp/ql/src/semmle/code/cpp/security/FlowSources.qll

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,38 @@ import semmle.code.cpp.models.interfaces.FlowSource
99

1010
/** A data flow source of remote user input. */
1111
abstract class RemoteFlowSource extends DataFlow::Node {
12+
/** Gets a string that describes the type of this remote flow source. */
13+
abstract string getSourceType();
1214
}
1315

1416
private class TaintedReturnSource extends RemoteFlowSource {
17+
string sourceType;
1518
TaintedReturnSource() {
1619
exists(RemoteFlowFunction func, CallInstruction instr, FunctionOutput output |
1720
asInstruction() = instr and
1821
instr.getStaticCallTarget() = func and
19-
func.hasFlowSource(output) and
22+
func.hasRemoteFlowSource(output, sourceType) and
2023
output.isReturnValue()
2124
)
2225
}
26+
27+
override string getSourceType() {
28+
result = sourceType
29+
}
2330
}
2431

2532
private class TaintedParameterSource extends RemoteFlowSource {
33+
string sourceType;
2634
TaintedParameterSource() {
2735
exists(RemoteFlowFunction func, WriteSideEffectInstruction instr, FunctionOutput output |
2836
asInstruction() = instr and
2937
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
30-
func.hasFlowSource(output) and
38+
func.hasRemoteFlowSource(output, sourceType) and
3139
output.isParameterDeref(instr.getIndex())
3240
)
3341
}
42+
43+
override string getSourceType() {
44+
result = sourceType
45+
}
3446
}

0 commit comments

Comments
 (0)