Skip to content

Commit 4f23acf

Browse files
authored
Merge pull request github#2957 from MathiasVP/dataflow-dispatch-same-num-args
C++: Only return functions that match arguments in DataFlowDispatch::viableCallable
2 parents 57b3e6a + 0b082a4 commit 4f23acf

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ private module VirtualDispatch {
135135
exists(FunctionInstruction fi |
136136
this.flowsFrom(DataFlow::instructionNode(fi), _) and
137137
result = fi.getFunctionSymbol()
138+
) and
139+
(
140+
this.getNumberOfArguments() <= result.getEffectiveNumberOfParameters() and
141+
this.getNumberOfArguments() >= result.getEffectiveNumberOfParameters()
142+
or
143+
result.isVarargs()
138144
)
139145
}
140146
}

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
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/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
/**

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_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
/**

csharp/ql/src/semmle/code/csharp/ir/implementation/raw/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
/**

csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_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)