Skip to content

Commit 0a57767

Browse files
committed
C++: Data flow through StmtExpr
1 parent a2de057 commit 0a57767

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ void intArraySourceCaller2() {
495495
///////////////////////////////////////////////////////////////////////////////
496496

497497
void throughStmtExpr(int source1, int clean1) {
498-
sink( ({ source1; }) ); // tainted (FALSE NEGATIVE)
498+
sink( ({ source1; }) ); // tainted
499499
sink( ({ clean1; }) ); // clean
500500

501501
int local = ({
@@ -506,5 +506,5 @@ void throughStmtExpr(int source1, int clean1) {
506506
tmp = clean1;
507507
tmp;
508508
});
509-
sink(local); // tainted (FALSE NEGATIVE)
509+
sink(local); // tainted
510510
}

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)