Skip to content

Commit 618d9c3

Browse files
authored
Merge pull request github#4642 from geoffw0/memberfn
C++: Improve MemberFunction.qll data flows
2 parents da90717 + c4fe8df commit 618d9c3

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,11 @@ private predicate exprToExprStep_nocfg(Expr fromExpr, Expr toExpr) {
677677
exists(DataFlowFunction f, FunctionInput inModel, FunctionOutput outModel |
678678
f.hasDataFlow(inModel, outModel) and
679679
(
680+
exists(int iIn |
681+
inModel.isParameterDeref(iIn) and
682+
call.passesByReference(iIn, fromExpr)
683+
)
684+
or
680685
exists(int iIn |
681686
inModel.isParameter(iIn) and
682687
fromExpr = call.getArgument(iIn)

cpp/ql/src/semmle/code/cpp/models/implementations/MemberFunction.qll

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ class ConversionConstructorModel extends Constructor, TaintFunction {
3535
class CopyConstructorModel extends CopyConstructor, DataFlowFunction {
3636
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
3737
// data flow from the first constructor argument to the returned object
38-
(
39-
input.isParameter(0)
40-
or
41-
input.isParameterDeref(0)
42-
) and
38+
input.isParameterDeref(0) and
4339
(
4440
output.isReturnValue()
4541
or
@@ -54,11 +50,7 @@ class CopyConstructorModel extends CopyConstructor, DataFlowFunction {
5450
class MoveConstructorModel extends MoveConstructor, DataFlowFunction {
5551
override predicate hasDataFlow(FunctionInput input, FunctionOutput output) {
5652
// data flow from the first constructor argument to the returned object
57-
(
58-
input.isParameter(0)
59-
or
60-
input.isParameterDeref(0)
61-
) and
53+
input.isParameterDeref(0) and
6254
(
6355
output.isReturnValue()
6456
or

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,10 +5113,11 @@
51135113
| swap1.cpp:109:5:109:30 | ... = ... | swap1.cpp:111:20:111:24 | data1 | |
51145114
| swap1.cpp:109:5:109:30 | ... = ... | swap1.cpp:115:18:115:22 | data1 | |
51155115
| swap1.cpp:109:23:109:28 | call to source | swap1.cpp:109:5:109:30 | ... = ... | |
5116-
| swap1.cpp:113:31:113:39 | call to move | swap1.cpp:113:31:113:51 | call to Class | |
5116+
| swap1.cpp:113:31:113:39 | call to move | swap1.cpp:113:31:113:51 | call to Class | TAINT |
51175117
| swap1.cpp:113:31:113:39 | ref arg call to move | swap1.cpp:113:41:113:49 | move_from [inner post update] | |
51185118
| swap1.cpp:113:31:113:51 | call to Class | swap1.cpp:115:10:115:16 | move_to | |
51195119
| swap1.cpp:113:41:113:49 | move_from | swap1.cpp:113:31:113:39 | call to move | |
5120+
| swap1.cpp:113:41:113:49 | move_from | swap1.cpp:113:31:113:51 | call to Class | |
51205121
| swap1.cpp:120:23:120:23 | x | swap1.cpp:122:5:122:5 | x | |
51215122
| swap1.cpp:120:23:120:23 | x | swap1.cpp:124:10:124:10 | x | |
51225123
| swap1.cpp:120:23:120:23 | x | swap1.cpp:127:19:127:19 | x | |
@@ -5279,10 +5280,11 @@
52795280
| swap2.cpp:109:5:109:30 | ... = ... | swap2.cpp:111:20:111:24 | data1 | |
52805281
| swap2.cpp:109:5:109:30 | ... = ... | swap2.cpp:115:18:115:22 | data1 | |
52815282
| swap2.cpp:109:23:109:28 | call to source | swap2.cpp:109:5:109:30 | ... = ... | |
5282-
| swap2.cpp:113:31:113:39 | call to move | swap2.cpp:113:31:113:51 | call to Class | |
5283+
| swap2.cpp:113:31:113:39 | call to move | swap2.cpp:113:31:113:51 | call to Class | TAINT |
52835284
| swap2.cpp:113:31:113:39 | ref arg call to move | swap2.cpp:113:41:113:49 | move_from [inner post update] | |
52845285
| swap2.cpp:113:31:113:51 | call to Class | swap2.cpp:115:10:115:16 | move_to | |
52855286
| swap2.cpp:113:41:113:49 | move_from | swap2.cpp:113:31:113:39 | call to move | |
5287+
| swap2.cpp:113:41:113:49 | move_from | swap2.cpp:113:31:113:51 | call to Class | |
52865288
| swap2.cpp:120:23:120:23 | x | swap2.cpp:122:5:122:5 | x | |
52875289
| swap2.cpp:120:23:120:23 | x | swap2.cpp:124:10:124:10 | x | |
52885290
| swap2.cpp:120:23:120:23 | x | swap2.cpp:127:19:127:19 | x | |

0 commit comments

Comments
 (0)