Skip to content

Commit ef47563

Browse files
committed
CPP: Support flow of pointed-to things through function calls.
1 parent 04af2ac commit ef47563

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,14 @@ private predicate exprToExprStep_nocfg(Expr fromExpr, Expr toExpr) {
602602
exists(DataFlowFunction f, FunctionInput inModel, FunctionOutput outModel, int iIn |
603603
call.getTarget() = f and
604604
f.hasDataFlow(inModel, outModel) and
605-
outModel.isReturnValue() and
606-
inModel.isParameter(iIn) and
607-
fromExpr = call.getArgument(iIn)
605+
fromExpr = call.getArgument(iIn) and
606+
(
607+
inModel.isParameter(iIn) and
608+
outModel.isReturnValue()
609+
or
610+
inModel.isParameterDeref(iIn) and
611+
outModel.isReturnValueDeref()
612+
)
608613
)
609614
)
610615
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
| taint.cpp:170:10:170:15 | ref arg buffer | taint.cpp:171:8:171:13 | buffer | |
145145
| taint.cpp:170:10:170:15 | ref arg buffer | taint.cpp:172:10:172:15 | buffer | |
146146
| taint.cpp:170:10:170:15 | ref arg buffer | taint.cpp:173:8:173:13 | buffer | |
147+
| taint.cpp:170:18:170:26 | Hello, | taint.cpp:170:3:170:8 | call to strcpy | |
147148
| taint.cpp:170:18:170:26 | Hello, | taint.cpp:170:10:170:15 | ref arg buffer | TAINT |
148149
| taint.cpp:171:8:171:13 | ref arg buffer | taint.cpp:172:10:172:15 | buffer | |
149150
| taint.cpp:171:8:171:13 | ref arg buffer | taint.cpp:173:8:173:13 | buffer | |
@@ -163,6 +164,8 @@
163164
| taint.cpp:194:9:194:10 | ref arg & ... | taint.cpp:194:2:194:7 | call to memcpy | |
164165
| taint.cpp:194:9:194:10 | ref arg & ... | taint.cpp:195:7:195:7 | x | |
165166
| taint.cpp:194:10:194:10 | x | taint.cpp:194:9:194:10 | & ... | |
167+
| taint.cpp:194:13:194:18 | ref arg source | taint.cpp:194:2:194:7 | call to memcpy | |
168+
| taint.cpp:194:13:194:18 | source | taint.cpp:194:2:194:7 | call to memcpy | |
166169
| taint.cpp:194:13:194:18 | source | taint.cpp:194:9:194:10 | ref arg & ... | TAINT |
167170
| taint.cpp:194:21:194:31 | sizeof(int) | taint.cpp:194:9:194:10 | ref arg & ... | TAINT |
168171
| taint.cpp:207:6:207:11 | call to source | taint.cpp:207:2:207:13 | ... = ... | |
@@ -328,8 +331,10 @@
328331
| taint.cpp:365:24:365:29 | source | taint.cpp:371:14:371:19 | source | |
329332
| taint.cpp:369:6:369:11 | call to strdup | taint.cpp:369:2:369:19 | ... = ... | |
330333
| taint.cpp:369:6:369:11 | call to strdup | taint.cpp:372:7:372:7 | a | |
334+
| taint.cpp:369:13:369:18 | source | taint.cpp:369:6:369:11 | call to strdup | |
331335
| taint.cpp:370:6:370:11 | call to strdup | taint.cpp:370:2:370:27 | ... = ... | |
332336
| taint.cpp:370:6:370:11 | call to strdup | taint.cpp:373:7:373:7 | b | |
337+
| taint.cpp:370:13:370:26 | hello, world | taint.cpp:370:6:370:11 | call to strdup | |
333338
| taint.cpp:371:6:371:12 | call to strndup | taint.cpp:371:2:371:25 | ... = ... | |
334339
| taint.cpp:371:6:371:12 | call to strndup | taint.cpp:374:7:374:7 | c | |
335340
| taint.cpp:377:23:377:28 | source | taint.cpp:381:30:381:35 | source | |
@@ -338,5 +343,7 @@
338343
| taint.cpp:385:27:385:32 | source | taint.cpp:389:13:389:18 | source | |
339344
| taint.cpp:389:6:389:11 | call to wcsdup | taint.cpp:389:2:389:19 | ... = ... | |
340345
| taint.cpp:389:6:389:11 | call to wcsdup | taint.cpp:391:7:391:7 | a | |
346+
| taint.cpp:389:13:389:18 | source | taint.cpp:389:6:389:11 | call to wcsdup | |
341347
| taint.cpp:390:6:390:11 | call to wcsdup | taint.cpp:390:2:390:28 | ... = ... | |
342348
| taint.cpp:390:6:390:11 | call to wcsdup | taint.cpp:392:7:392:7 | b | |
349+
| taint.cpp:390:13:390:27 | hello, world | taint.cpp:390:6:390:11 | call to wcsdup | |

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ void test_strdup(char *source)
369369
a = strdup(source);
370370
b = strdup("hello, world");
371371
c = strndup(source, 100);
372-
sink(a); // tainted [NOT DETECTED]
372+
sink(a); // tainted
373373
sink(b);
374374
sink(c); // tainted [NOT DETECTED]
375375
}
@@ -388,6 +388,6 @@ void test_wcsdup(wchar_t *source)
388388

389389
a = wcsdup(source);
390390
b = wcsdup(L"hello, world");
391-
sink(a); // tainted [NOT DETECTED]
391+
sink(a); // tainted
392392
sink(b);
393393
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@
3737
| taint.cpp:350:7:350:7 | t | taint.cpp:330:6:330:11 | call to source |
3838
| taint.cpp:351:7:351:7 | a | taint.cpp:330:6:330:11 | call to source |
3939
| taint.cpp:352:7:352:7 | b | taint.cpp:330:6:330:11 | call to source |
40+
| taint.cpp:372:7:372:7 | a | taint.cpp:365:24:365:29 | source |
41+
| taint.cpp:391:7:391:7 | a | taint.cpp:385:27:385:32 | source |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@
2525
| taint.cpp:350:7:350:7 | taint.cpp:330:6:330:11 | AST only |
2626
| taint.cpp:351:7:351:7 | taint.cpp:330:6:330:11 | AST only |
2727
| taint.cpp:352:7:352:7 | taint.cpp:330:6:330:11 | AST only |
28+
| taint.cpp:372:7:372:7 | taint.cpp:365:24:365:29 | AST only |
29+
| taint.cpp:391:7:391:7 | taint.cpp:385:27:385:32 | AST only |

0 commit comments

Comments
 (0)