Skip to content

Commit 246c486

Browse files
committed
C++: Fix FP by ensuring that the targeted constructor has at least as many parameters as the number of forwarded arguments.
1 parent cca9f3f commit 246c486

3 files changed

Lines changed: 5 additions & 15 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ predicate forwardingCallTargetsConstructor(
607607
CallInstruction call, Cpp::Constructor constructor, int start
608608
) {
609609
exists(int numberOfForwardedArguments |
610+
numberOfForwardedArguments <= constructor.getNumberOfParameters()
611+
or
612+
constructor.isVarargs()
613+
|
610614
External::forwards(call.getStaticCallTarget(), constructor, start) and
611615
call.getNumberOfPositionalArguments() = start + numberOfForwardedArguments and
612616
forall(int i | i = [0 .. constructor.getNumberOfParameters() - 1] |

‎cpp/ql/test/library-tests/dataflow/external-models/flow.expected‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,13 @@ edges
407407
| test.cpp:418:51:418:56 | second | test.cpp:418:3:418:28 | *ElementWithOverloadedArity [post update] [x] | provenance | |
408408
| test.cpp:422:11:422:19 | call to ymlSource | test.cpp:422:11:422:19 | call to ymlSource | provenance | Src:MaD:48 |
409409
| test.cpp:422:11:422:19 | call to ymlSource | test.cpp:425:18:425:18 | *x | provenance | |
410-
| test.cpp:422:11:422:19 | call to ymlSource | test.cpp:430:18:430:18 | *x | provenance | |
411410
| test.cpp:422:11:422:19 | call to ymlSource | test.cpp:435:21:435:21 | *x | provenance | |
412411
| test.cpp:425:5:425:5 | emplace output argument [element, x] | test.cpp:426:13:426:13 | *c [element, x] | provenance | |
413412
| test.cpp:425:18:425:18 | *x | test.cpp:417:34:417:38 | first | provenance | |
414413
| test.cpp:425:18:425:18 | *x | test.cpp:425:5:425:5 | emplace output argument [element, x] | provenance | |
415414
| test.cpp:426:13:426:13 | *c [element, x] | test.cpp:426:18:426:20 | *call to get [x] | provenance | MaD:87 |
416415
| test.cpp:426:18:426:20 | *call to get [x] | test.cpp:426:21:426:21 | x | provenance | |
417416
| test.cpp:426:21:426:21 | x | test.cpp:426:21:426:21 | x | provenance | Sink:MaD:3 |
418-
| test.cpp:430:5:430:5 | emplace output argument [element, x] | test.cpp:431:13:431:13 | *c [element, x] | provenance | |
419-
| test.cpp:430:18:430:18 | *x | test.cpp:417:34:417:38 | first | provenance | |
420-
| test.cpp:430:18:430:18 | *x | test.cpp:430:5:430:5 | emplace output argument [element, x] | provenance | |
421-
| test.cpp:431:13:431:13 | *c [element, x] | test.cpp:431:18:431:20 | *call to get [x] | provenance | MaD:87 |
422-
| test.cpp:431:18:431:20 | *call to get [x] | test.cpp:431:21:431:21 | x | provenance | |
423-
| test.cpp:431:21:431:21 | x | test.cpp:431:21:431:21 | x | provenance | Sink:MaD:3 |
424417
| test.cpp:435:5:435:5 | emplace output argument [element, x] | test.cpp:436:13:436:13 | *c [element, x] | provenance | |
425418
| test.cpp:435:21:435:21 | *x | test.cpp:418:39:418:44 | second | provenance | |
426419
| test.cpp:435:21:435:21 | *x | test.cpp:435:5:435:5 | emplace output argument [element, x] | provenance | |
@@ -951,12 +944,6 @@ nodes
951944
| test.cpp:426:18:426:20 | *call to get [x] | semmle.label | *call to get [x] |
952945
| test.cpp:426:21:426:21 | x | semmle.label | x |
953946
| test.cpp:426:21:426:21 | x | semmle.label | x |
954-
| test.cpp:430:5:430:5 | emplace output argument [element, x] | semmle.label | emplace output argument [element, x] |
955-
| test.cpp:430:18:430:18 | *x | semmle.label | *x |
956-
| test.cpp:431:13:431:13 | *c [element, x] | semmle.label | *c [element, x] |
957-
| test.cpp:431:18:431:20 | *call to get [x] | semmle.label | *call to get [x] |
958-
| test.cpp:431:21:431:21 | x | semmle.label | x |
959-
| test.cpp:431:21:431:21 | x | semmle.label | x |
960947
| test.cpp:435:5:435:5 | emplace output argument [element, x] | semmle.label | emplace output argument [element, x] |
961948
| test.cpp:435:21:435:21 | *x | semmle.label | *x |
962949
| test.cpp:436:13:436:13 | *c [element, x] | semmle.label | *c [element, x] |
@@ -1187,6 +1174,5 @@ subpaths
11871174
| test.cpp:362:15:362:15 | *x | test.cpp:341:30:341:32 | arg | test.cpp:341:3:341:22 | *this [Return] [s] | test.cpp:362:5:362:5 | forward output argument [s] |
11881175
| test.cpp:371:15:371:16 | *ul | test.cpp:345:38:345:40 | arg | test.cpp:345:3:345:22 | *this [Return] [ul] | test.cpp:371:5:371:5 | forward output argument [ul] |
11891176
| test.cpp:425:18:425:18 | *x | test.cpp:417:34:417:38 | first | test.cpp:417:3:417:28 | *this [Return] [x] | test.cpp:425:5:425:5 | emplace output argument [element, x] |
1190-
| test.cpp:430:18:430:18 | *x | test.cpp:417:34:417:38 | first | test.cpp:417:3:417:28 | *this [Return] [x] | test.cpp:430:5:430:5 | emplace output argument [element, x] |
11911177
| test.cpp:435:21:435:21 | *x | test.cpp:418:39:418:44 | second | test.cpp:418:3:418:28 | *this [Return] [x] | test.cpp:435:5:435:5 | emplace output argument [element, x] |
11921178
testFailures

‎cpp/ql/test/library-tests/dataflow/external-models/test.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ void forward_test_constructor_arity() {
428428
{
429429
Container<ElementWithOverloadedArity> c;
430430
c.emplace(0, x, 0);
431-
ymlSink(c.get().x); // $ SPURIOUS: ir
431+
ymlSink(c.get().x); // clean
432432
}
433433
{
434434
Container<ElementWithOverloadedArity> c;

0 commit comments

Comments
 (0)