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

Skip to content

Commit 4728cf5

Browse files
committed
C++: Allow the 'x' in 'x = source()' to be marked as a sink in MaD.
1 parent cd41a1c commit 4728cf5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

cpp/ql/lib/semmle/code/cpp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
99
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
1010
private import semmle.code.cpp.ir.dataflow.internal.DataFlowImplSpecific as DataFlowImplSpecific
1111
private import semmle.code.cpp.dataflow.ExternalFlow
12+
private import semmle.code.cpp.ir.IR
1213

1314
module Input implements InputSig<DataFlowImplSpecific::CppDataFlow> {
1415
class SummarizedCallableBase = Function;
@@ -165,6 +166,21 @@ module SourceSinkInterpretationInput implements
165166
c = "" and
166167
e.getQualifier() = n.asExpr()
167168
or
169+
// Allow variables (without a qualifier) to be picked as input nodes.
170+
// We could simply do this as `e = n.asExpr()`, but that would not allow
171+
// us to pick `x` as a sink in an example such as `x = source()` (but
172+
// only subsequent uses of `x`) since the variable access on `x` doesn't
173+
// actually load the value of `x`. So instead, we pick the instruction
174+
// node corresponding to the generated `StoreInstruction` and use the
175+
// expression associated with the destination instruction. This means
176+
// that the `x` in `x = source()` can be marked as an input.
177+
c = "" and
178+
not exists(e.getQualifier()) and
179+
exists(StoreInstruction store |
180+
store.getDestinationAddress().getUnconvertedResultExpression() = e and
181+
n.asInstruction() = store
182+
)
183+
or
168184
// Allow post update nodes to be picked as input nodes when the `input` column
169185
// of the row is `PostUpdate`.
170186
c = "PostUpdate" and

0 commit comments

Comments
 (0)