Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 01a81a9

Browse files
committed
C++: Repair the 'FlowSources' library in preparation for IR-based use-use dataflow.
1 parent d62ae96 commit 01a81a9

1 file changed

Lines changed: 15 additions & 62 deletions

File tree

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

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import cpp
66
import semmle.code.cpp.ir.dataflow.DataFlow
77
private import semmle.code.cpp.ir.IR
88
import semmle.code.cpp.models.interfaces.FlowSource
9+
private import semmle.code.cpp.ir.dataflow.internal.ModelUtil
910

1011
/** A data flow source of user input, whether local or remote. */
1112
abstract class FlowSource extends DataFlow::Node {
@@ -19,68 +20,28 @@ abstract class RemoteFlowSource extends FlowSource { }
1920
/** A data flow source of local user input. */
2021
abstract class LocalFlowSource extends FlowSource { }
2122

22-
private class RemoteReturnSource extends RemoteFlowSource {
23+
private class RemoteModelSource extends RemoteFlowSource {
2324
string sourceType;
2425

25-
RemoteReturnSource() {
26-
exists(RemoteFlowSourceFunction func, CallInstruction instr, FunctionOutput output |
27-
this.asInstruction() = instr and
28-
instr.getStaticCallTarget() = func and
26+
RemoteModelSource() {
27+
exists(CallInstruction call, RemoteFlowSourceFunction func, FunctionOutput output |
28+
call.getStaticCallTarget() = func and
2929
func.hasRemoteFlowSource(output, sourceType) and
30-
(
31-
output.isReturnValue()
32-
or
33-
output.isReturnValueDeref()
34-
)
30+
this = callOutput(call, output)
3531
)
3632
}
3733

3834
override string getSourceType() { result = sourceType }
3935
}
4036

41-
private class RemoteParameterSource extends RemoteFlowSource {
37+
private class LocalModelSource extends LocalFlowSource {
4238
string sourceType;
4339

44-
RemoteParameterSource() {
45-
exists(RemoteFlowSourceFunction func, WriteSideEffectInstruction instr, FunctionOutput output |
46-
this.asInstruction() = instr and
47-
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
48-
func.hasRemoteFlowSource(output, sourceType) and
49-
output.isParameterDerefOrQualifierObject(instr.getIndex())
50-
)
51-
}
52-
53-
override string getSourceType() { result = sourceType }
54-
}
55-
56-
private class LocalReturnSource extends LocalFlowSource {
57-
string sourceType;
58-
59-
LocalReturnSource() {
60-
exists(LocalFlowSourceFunction func, CallInstruction instr, FunctionOutput output |
61-
this.asInstruction() = instr and
62-
instr.getStaticCallTarget() = func and
63-
func.hasLocalFlowSource(output, sourceType) and
64-
(
65-
output.isReturnValue()
66-
or
67-
output.isReturnValueDeref()
68-
)
69-
)
70-
}
71-
72-
override string getSourceType() { result = sourceType }
73-
}
74-
75-
private class LocalParameterSource extends LocalFlowSource {
76-
string sourceType;
77-
78-
LocalParameterSource() {
79-
exists(LocalFlowSourceFunction func, WriteSideEffectInstruction instr, FunctionOutput output |
80-
this.asInstruction() = instr and
81-
instr.getPrimaryInstruction().(CallInstruction).getStaticCallTarget() = func and
40+
LocalModelSource() {
41+
exists(CallInstruction call, LocalFlowSourceFunction func, FunctionOutput output |
42+
call.getStaticCallTarget() = func and
8243
func.hasLocalFlowSource(output, sourceType) and
83-
output.isParameterDerefOrQualifierObject(instr.getIndex())
44+
this = callOutput(call, output)
8445
)
8546
}
8647

@@ -109,18 +70,10 @@ private class RemoteParameterSink extends RemoteFlowSink {
10970
string sourceType;
11071

11172
RemoteParameterSink() {
112-
exists(RemoteFlowSinkFunction func, FunctionInput input, CallInstruction call, int index |
113-
func.hasRemoteFlowSink(input, sourceType) and call.getStaticCallTarget() = func
114-
|
115-
exists(ReadSideEffectInstruction read |
116-
call = read.getPrimaryInstruction() and
117-
read.getIndex() = index and
118-
this.asOperand() = read.getSideEffectOperand() and
119-
input.isParameterDerefOrQualifierObject(index)
120-
)
121-
or
122-
input.isParameterOrQualifierAddress(index) and
123-
this.asOperand() = call.getArgumentOperand(index)
73+
exists(CallInstruction call, RemoteFlowSinkFunction func, FunctionInput input |
74+
call.getStaticCallTarget() = func and
75+
func.hasRemoteFlowSink(input, sourceType) and
76+
this = callInput(call, input)
12477
)
12578
}
12679

0 commit comments

Comments
 (0)