Skip to content

Commit 46ce228

Browse files
committed
C++: Add instruction for CheckedConvertOrNull and handle it in alias analysis and data flow
1 parent 928b0c5 commit 46ce228

File tree

6 files changed

+21
-0
lines changed

6 files changed

+21
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ private predicate simpleInstructionLocalFlowStep(Instruction iFrom, Instruction
268268
iTo.(PhiInstruction).getAnOperand().getDef() = iFrom or
269269
// Treat all conversions as flow, even conversions between different numeric types.
270270
iTo.(ConvertInstruction).getUnary() = iFrom or
271+
iTo.(CheckedConvertOrNullInstruction).getUnary() = iFrom or
271272
iTo.(InheritanceConversionInstruction).getUnary() = iFrom or
272273
// A chi instruction represents a point where a new value (the _partial_
273274
// operand) may overwrite an old value (the _total_ operand), but the alias

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ class ConvertInstruction extends UnaryInstruction {
947947
ConvertInstruction() { getOpcode() instanceof Opcode::Convert }
948948
}
949949

950+
class CheckedConvertOrNullInstruction extends UnaryInstruction {
951+
CheckedConvertOrNullInstruction() { getOpcode() instanceof Opcode::CheckedConvertOrNull }
952+
}
953+
950954
/**
951955
* Represents an instruction that converts between two addresses
952956
* related by inheritance.

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/AliasAnalysis.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ private predicate operandIsPropagated(Operand operand, IntValue bitOffset) {
9696
bitOffset = Ints::mul(convert.getDerivation().getByteOffset(), 8)
9797
)
9898
or
99+
// Conversion using dynamic_cast results in an unknown offset
100+
instr instanceof CheckedConvertOrNullInstruction and
101+
bitOffset = Ints::unknown()
102+
or
99103
// Converting to a derived class subtracts the offset of the base class.
100104
exists(ConvertToDerivedInstruction convert |
101105
convert = instr and

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ class ConvertInstruction extends UnaryInstruction {
947947
ConvertInstruction() { getOpcode() instanceof Opcode::Convert }
948948
}
949949

950+
class CheckedConvertOrNullInstruction extends UnaryInstruction {
951+
CheckedConvertOrNullInstruction() { getOpcode() instanceof Opcode::CheckedConvertOrNull }
952+
}
953+
950954
/**
951955
* Represents an instruction that converts between two addresses
952956
* related by inheritance.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,10 @@ class ConvertInstruction extends UnaryInstruction {
947947
ConvertInstruction() { getOpcode() instanceof Opcode::Convert }
948948
}
949949

950+
class CheckedConvertOrNullInstruction extends UnaryInstruction {
951+
CheckedConvertOrNullInstruction() { getOpcode() instanceof Opcode::CheckedConvertOrNull }
952+
}
953+
950954
/**
951955
* Represents an instruction that converts between two addresses
952956
* related by inheritance.

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/AliasAnalysis.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ private predicate operandIsPropagated(Operand operand, IntValue bitOffset) {
9696
bitOffset = Ints::mul(convert.getDerivation().getByteOffset(), 8)
9797
)
9898
or
99+
// Conversion using dynamic_cast results in an unknown offset
100+
instr instanceof CheckedConvertOrNullInstruction and
101+
bitOffset = Ints::unknown()
102+
or
99103
// Converting to a derived class subtracts the offset of the base class.
100104
exists(ConvertToDerivedInstruction convert |
101105
convert = instr and

0 commit comments

Comments
 (0)