Skip to content

Commit 14d836b

Browse files
committed
C++: should only match those functions that has the same number of parameters as the call has arguments.
1 parent 228bd73 commit 14d836b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowDispatch.qll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ Function viableCallable(CallInstruction call) {
2222
)
2323
or
2424
// Virtual dispatch
25-
result = call.(VirtualDispatch::DataSensitiveCall).resolve()
25+
result = call.(VirtualDispatch::DataSensitiveCall).resolve() and
26+
(
27+
call.getNumberOfArguments() <= result.getEffectiveNumberOfParameters() and
28+
call.getNumberOfArguments() >= result.getEffectiveNumberOfParameters()
29+
or
30+
result.isVarargs()
31+
)
2632
}
2733

2834
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,11 @@ class CallInstruction extends Instruction {
12021202
final Instruction getPositionalArgument(int index) {
12031203
result = getPositionalArgumentOperand(index).getDef()
12041204
}
1205+
1206+
/**
1207+
* Gets the number of arguments of the call, including the `this` pointer, if any.
1208+
*/
1209+
final int getNumberOfArguments() { result = count(this.getAnArgumentOperand()) }
12051210
}
12061211

12071212
/**

0 commit comments

Comments
 (0)