Skip to content

Commit 8dd0bdb

Browse files
committed
C++: Rename 'fst' and 'snd' to 'incoming' and 'outgoing'.
1 parent 484f761 commit 8dd0bdb

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

cpp/ql/src/Security/CWE/CWE-078/ExecTainted.ql

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import semmle.code.cpp.models.implementations.Strcat
2525
import DataFlow::PathGraph
2626

2727
/**
28-
* Holds if `fst` is a string that is used in a format or concatenation function resulting in `snd`,
29-
* and is *not* placed at the start of the resulting string. This indicates that the author did not
30-
* expect `fst` to control what program is run if the resulting string is eventually interpreted as
31-
* a command line, for example as an argument to `system`.
28+
* Holds if `incoming` is a string that is used in a format or concatenation function resulting
29+
* in `outgoing`, and is *not* placed at the start of the resulting string. This indicates that
30+
* the author did not expect `incoming` to control what program is run if the resulting string
31+
* is eventually interpreted as a command line, for example as an argument to `system`.
3232
*/
33-
predicate interestingConcatenation(DataFlow::Node fst, DataFlow::Node snd) {
33+
predicate interestingConcatenation(DataFlow::Node incoming, DataFlow::Node outgoing) {
3434
exists(FormattingFunctionCall call, int index, FormatLiteral literal |
35-
fst.asIndirectArgument() = call.getConversionArgument(index) and
36-
snd.asDefiningArgument() = call.getOutputArgument(false) and
35+
incoming.asIndirectArgument() = call.getConversionArgument(index) and
36+
outgoing.asDefiningArgument() = call.getOutputArgument(false) and
3737
literal = call.getFormat() and
3838
not literal.getConvSpecOffset(index) = 0 and
3939
literal.getConversionChar(index) = ["s", "S"]
@@ -42,16 +42,16 @@ predicate interestingConcatenation(DataFlow::Node fst, DataFlow::Node snd) {
4242
// strcat and friends
4343
exists(StrcatFunction strcatFunc, Call call |
4444
call.getTarget() = strcatFunc and
45-
fst.asIndirectArgument() = call.getArgument(strcatFunc.getParamSrc()) and
46-
snd.asDefiningArgument() = call.getArgument(strcatFunc.getParamDest())
45+
incoming.asIndirectArgument() = call.getArgument(strcatFunc.getParamSrc()) and
46+
outgoing.asDefiningArgument() = call.getArgument(strcatFunc.getParamDest())
4747
)
4848
or
4949
exists(Call call, Operator op |
5050
call.getTarget() = op and
5151
op.hasQualifiedName("std", "operator+") and
5252
op.getType().(UserType).hasQualifiedName("std", "basic_string") and
53-
fst.asIndirectArgument() = call.getArgument(1) and // left operand
54-
call = snd.asInstruction().getUnconvertedResultExpression()
53+
incoming.asIndirectArgument() = call.getArgument(1) and // left operand
54+
call = outgoing.asInstruction().getUnconvertedResultExpression()
5555
)
5656
}
5757

@@ -60,22 +60,23 @@ class ConcatState extends DataFlow::FlowState {
6060
}
6161

6262
class ExecState extends DataFlow::FlowState {
63-
DataFlow::Node fst;
64-
DataFlow::Node snd;
63+
DataFlow::Node incoming;
64+
DataFlow::Node outgoing;
6565

6666
ExecState() {
6767
this =
68-
"ExecState (" + fst.getLocation() + " | " + fst + ", " + snd.getLocation() + " | " + snd + ")" and
69-
interestingConcatenation(pragma[only_bind_into](fst), pragma[only_bind_into](snd))
68+
"ExecState (" + incoming.getLocation() + " | " + incoming + ", " + outgoing.getLocation() +
69+
" | " + outgoing + ")" and
70+
interestingConcatenation(pragma[only_bind_into](incoming), pragma[only_bind_into](outgoing))
7071
}
7172

72-
DataFlow::Node getFstNode() { result = fst }
73+
DataFlow::Node getIncomingNode() { result = incoming }
7374

74-
DataFlow::Node getSndNode() { result = snd }
75+
DataFlow::Node getOutgoingNode() { result = outgoing }
7576

7677
/** Holds if this is a possible `ExecState` for `sink`. */
7778
predicate isFeasibleForSink(DataFlow::Node sink) {
78-
any(ExecStateConfiguration conf).hasFlow(snd, sink)
79+
any(ExecStateConfiguration conf).hasFlow(outgoing, sink)
7980
}
8081
}
8182

@@ -93,7 +94,7 @@ class ExecStateConfiguration extends TaintTracking2::Configuration {
9394
ExecStateConfiguration() { this = "ExecStateConfiguration" }
9495

9596
override predicate isSource(DataFlow::Node source) {
96-
exists(ExecState state | state.getSndNode() = source)
97+
any(ExecState state).getOutgoingNode() = source
9798
}
9899

99100
override predicate isSink(DataFlow::Node sink) { isSinkImpl(sink, _, _) }
@@ -121,8 +122,8 @@ class ExecTaintConfiguration extends TaintTracking::Configuration {
121122
DataFlow::FlowState state2
122123
) {
123124
state1 instanceof ConcatState and
124-
state2.(ExecState).getFstNode() = node1 and
125-
state2.(ExecState).getSndNode() = node2
125+
state2.(ExecState).getIncomingNode() = node1 and
126+
state2.(ExecState).getOutgoingNode() = node2
126127
}
127128

128129
override predicate isSanitizer(DataFlow::Node node, DataFlow::FlowState state) {
@@ -146,7 +147,7 @@ where
146147
conf.hasFlowPath(sourceNode, sinkNode) and
147148
taintCause = sourceNode.getNode().(FlowSource).getSourceType() and
148149
isSinkImpl(sinkNode.getNode(), command, callChain) and
149-
concatResult = sinkNode.getState().(ExecState).getSndNode()
150+
concatResult = sinkNode.getState().(ExecState).getOutgoingNode()
150151
select command, sourceNode, sinkNode,
151152
"This argument to an OS command is derived from $@, dangerously concatenated into $@, and then passed to "
152153
+ callChain + ".", sourceNode, "user input (" + taintCause + ")", concatResult,

0 commit comments

Comments
 (0)