Skip to content

Commit 6939373

Browse files
authored
Merge pull request #1047 from jbj/dataflow-StmtExpr
C++: Data flow through StmtExpr
2 parents 9469917 + 0a57767 commit 6939373

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowUtil.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ private predicate exprToExprStep_nocfg(Expr fromExpr, Expr toExpr) {
275275
fromExpr = op.getOperand()
276276
)
277277
or
278+
toExpr = any(StmtExpr stmtExpr |
279+
fromExpr = stmtExpr.getResultExpr()
280+
)
281+
or
278282
toExpr = any(Call call |
279283
exists(DataFlowFunction f, FunctionInput inModel , FunctionOutput outModel, int iIn |
280284
call.getTarget() = f and

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,20 @@ void intArraySourceCaller2() {
491491
sink(local); // tainted
492492
sink(*local); // clean
493493
}
494+
495+
///////////////////////////////////////////////////////////////////////////////
496+
497+
void throughStmtExpr(int source1, int clean1) {
498+
sink( ({ source1; }) ); // tainted
499+
sink( ({ clean1; }) ); // clean
500+
501+
int local = ({
502+
int tmp;
503+
if (clean1)
504+
tmp = source1;
505+
else
506+
tmp = clean1;
507+
tmp;
508+
});
509+
sink(local); // tainted
510+
}

cpp/ql/test/library-tests/dataflow/dataflow-tests/test.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
| test.cpp:478:8:478:12 | local | test.cpp:477:20:477:24 | ref arg local |
3636
| test.cpp:485:8:485:12 | local | test.cpp:484:18:484:23 | ref arg & ... |
3737
| test.cpp:491:8:491:12 | local | test.cpp:490:18:490:22 | ref arg local |
38+
| test.cpp:498:9:498:22 | (statement expression) | test.cpp:497:26:497:32 | source1 |
39+
| test.cpp:509:8:509:12 | local | test.cpp:497:26:497:32 | source1 |
3840
| true_upon_entry.cpp:21:8:21:8 | x | true_upon_entry.cpp:17:11:17:16 | call to source |
3941
| true_upon_entry.cpp:29:8:29:8 | x | true_upon_entry.cpp:27:9:27:14 | call to source |
4042
| true_upon_entry.cpp:39:8:39:8 | x | true_upon_entry.cpp:33:11:33:16 | call to source |

cpp/ql/test/library-tests/dataflow/dataflow-tests/test_diff.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
| test.cpp:477:20:477:24 | test.cpp:478:8:478:12 | AST only |
1818
| test.cpp:484:18:484:23 | test.cpp:485:8:485:12 | AST only |
1919
| test.cpp:490:18:490:22 | test.cpp:491:8:491:12 | AST only |
20+
| test.cpp:497:26:497:32 | test.cpp:498:9:498:22 | AST only |
21+
| test.cpp:497:26:497:32 | test.cpp:509:8:509:12 | AST only |
2022
| true_upon_entry.cpp:9:11:9:16 | true_upon_entry.cpp:13:8:13:8 | IR only |
2123
| true_upon_entry.cpp:62:11:62:16 | true_upon_entry.cpp:66:8:66:8 | IR only |
2224
| true_upon_entry.cpp:98:11:98:16 | true_upon_entry.cpp:105:8:105:8 | IR only |

0 commit comments

Comments
 (0)