Skip to content

Commit 522c629

Browse files
committed
C++: Move fix to adjustedSink to avoid generating too many instructions
1 parent 52bc25b commit 522c629

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

cpp/ql/src/semmle/code/cpp/ir/dataflow/DefaultTaintTracking.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ private Element adjustedSink(DataFlow::Node sink) {
335335
// For compatibility, send flow into a `NotExpr` even if it's part of a
336336
// short-circuiting condition and thus might get skipped.
337337
result.(NotExpr).getOperand() = sink.asExpr()
338+
or
339+
// Taint `e--` and `e++` when `e` is tainted.
340+
exists(PostfixCrementOperation crement |
341+
crement.getAnOperand() = sink.asExpr() and
342+
result = crement
343+
)
338344
}
339345

340346
predicate tainted(Expr source, Element tainted) {

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/internal/TranslatedExpr.qll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,9 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
24692469
expr instanceof PrefixCrementOperation and
24702470
not expr.isPRValueCategory() // is C++
24712471
or
2472+
// Because the load is on the `e` in `e++`.
2473+
expr instanceof PostfixCrementOperation
2474+
or
24722475
expr instanceof PointerDereferenceExpr
24732476
or
24742477
expr instanceof AddressOfExpr
@@ -2486,12 +2489,6 @@ predicate exprNeedsCopyIfNotLoaded(Expr expr) {
24862489
// TODO: simplify TranslatedStmtExpr too
24872490
) and
24882491
not exprImmediatelyDiscarded(expr)
2489-
or
2490-
// For certain expressions we want to keep the CopyValue instruction even though the result might
2491-
// not be needed, as we otherwise cannot get back the original expression. For now the only such
2492-
// expressions we have encountered are `e++` and `e--`.
2493-
// Because the load is on the `e` in `e++`.
2494-
expr instanceof PostfixCrementOperation
24952492
}
24962493

24972494
/**

0 commit comments

Comments
 (0)