Skip to content

Commit

Permalink
Merge pull request github#18827 from geoffw0/exectainted
Browse files Browse the repository at this point in the history
C++: Expand qldoc and tests for cpp/command-line-injection
  • Loading branch information
geoffw0 authored Feb 24, 2025
2 parents 1b2d842 + b6f9055 commit 08913c5
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 162 deletions.
18 changes: 16 additions & 2 deletions cpp/ql/src/Security/CWE/CWE-078/ExecTainted.ql
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ predicate interestingConcatenation(DataFlow::Node incoming, DataFlow::Node outgo
call.getTarget() = op and
op.hasQualifiedName("std", "operator+") and
op.getType().(UserType).hasQualifiedName("std", "basic_string") and
incoming.asIndirectArgument() = call.getArgument(1) and // left operand
incoming.asIndirectArgument() = call.getArgument(1) and // right operand
call = outgoing.asInstruction().getUnconvertedResultExpression()
)
}

/**
* A state will represent the most recent concatenation that occurred in the data flow.
* - `TConcatState` if the concetenation has not yet occurred.
* - `TExecState(incoming, outgoing)`, representing the concatenation of data from `incoming`
* into result `outgoing`.
*/
newtype TState =
TConcatState() or
TExecState(DataFlow::Node incoming, DataFlow::Node outgoing) {
Expand All @@ -74,7 +80,9 @@ class ExecState extends TExecState {

DataFlow::Node getOutgoingNode() { result = outgoing }

/** Holds if this is a possible `ExecState` for `sink`. */
/**
* Holds if this is a possible `ExecState` at `sink`, that is, if `outgoing` flows to `sink`.
*/
predicate isFeasibleForSink(DataFlow::Node sink) { ExecState::flow(outgoing, sink) }

string toString() { result = "ExecState" }
Expand Down Expand Up @@ -110,6 +118,12 @@ module ExecStateConfig implements DataFlow::ConfigSig {

module ExecState = TaintTracking::Global<ExecStateConfig>;

/**
* A full `TaintTracking` configuration from source to concatenation to sink, using a flow
* state to remember the concatenation. It's important that we track flow to the sink even though
* as soon as we reach the concatenation we know it will get there (due to the check of
* `isFeasibleForSink`), because this way we get a complete flow path.
*/
module ExecTaintConfig implements DataFlow::StateConfigSig {
class FlowState = TState;

Expand Down
Loading

0 comments on commit 08913c5

Please sign in to comment.