Skip to content

Commit 2c6bbd8

Browse files
committed
C++: Replace 'left' with 'small' and 'right' with 'large' for consistency.
1 parent efe3c0d commit 2c6bbd8

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/AllocationToInvalidPointer.qll

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ private module SizeBarrier {
105105
}
106106

107107
/**
108-
* Holds if `left <= right + k` holds if `g` evaluates to `testIsTrue`.
108+
* Holds if `small <= large + k` holds if `g` evaluates to `testIsTrue`.
109109
*/
110110
additional predicate isSink(
111-
DataFlow::Node left, DataFlow::Node right, IRGuardCondition g, int k, boolean testIsTrue
111+
DataFlow::Node small, DataFlow::Node large, IRGuardCondition g, int k, boolean testIsTrue
112112
) {
113-
// The sink is any "large" side of a relational comparison. i.e., the `right` expression
114-
// in a guard such as `left <= right + k`.
115-
g.comparesLt(left.asOperand(), right.asOperand(), k + 1, true, testIsTrue)
113+
// The sink is any "large" side of a relational comparison. i.e., the `large` expression
114+
// in a guard such as `small <= large + k`.
115+
g.comparesLt(small.asOperand(), large.asOperand(), k + 1, true, testIsTrue)
116116
}
117117

118118
predicate isSink(DataFlow::Node sink) { isSink(_, sink, _, _, _) }
@@ -128,34 +128,36 @@ private module SizeBarrier {
128128
}
129129

130130
/**
131-
* Holds if `left <= nRight + k` holds if `g` evaluates to `edge`.
131+
* Holds if `small <= large + k` holds if `g` evaluates to `edge`.
132132
*/
133133
private predicate operandGuardChecks(
134-
IRGuardCondition g, Operand left, DataFlow::Node right, int k, boolean edge
134+
IRGuardCondition g, Operand small, DataFlow::Node large, int k, boolean edge
135135
) {
136-
SizeBarrierFlow::flowTo(right) and
137-
SizeBarrierConfig::isSink(DataFlow::operandNode(left), right, g, k, edge)
136+
SizeBarrierFlow::flowTo(large) and
137+
SizeBarrierConfig::isSink(DataFlow::operandNode(small), large, g, k, edge)
138138
}
139139

140140
/**
141-
* Gets an instruction `instr` that is guarded by a check such as `instr <= left + delta` where
142-
* `left <= _ + k` and `left` is the "small side" of of a relational comparison that checks
143-
* whether `left <= size` where `size` is the size of an allocation.
141+
* Gets an instruction `instr` that is guarded by a check such as `instr <= small + delta` where
142+
* `small <= _ + k` and `small` is the "small side" of of a relational comparison that checks
143+
* whether `small <= size` where `size` is the size of an allocation.
144144
*/
145145
Instruction getABarrierInstruction0(int delta, int k) {
146-
exists(IRGuardCondition g, ValueNumber value, Operand left, boolean edge, DataFlow::Node right |
146+
exists(
147+
IRGuardCondition g, ValueNumber value, Operand small, boolean edge, DataFlow::Node large
148+
|
147149
// We know:
148150
// 1. result <= value + delta (by `bounded`)
149-
// 2. value <= right + k (by `operandGuardChecks`).
151+
// 2. value <= large + k (by `operandGuardChecks`).
150152
// So:
151153
// result <= value + delta (by 1.)
152-
// <= right + k + delta (by 2.)
153-
left = value.getAUse() and
154-
operandGuardChecks(pragma[only_bind_into](g), pragma[only_bind_into](left), right,
154+
// <= large + k + delta (by 2.)
155+
small = value.getAUse() and
156+
operandGuardChecks(pragma[only_bind_into](g), pragma[only_bind_into](small), large,
155157
pragma[only_bind_into](k), pragma[only_bind_into](edge)) and
156158
bounded(result, value.getAnInstruction(), delta) and
157159
g.controls(result.getBlock(), edge) and
158-
k < getASizeAddend(right)
160+
k < getASizeAddend(large)
159161
)
160162
}
161163

cpp/ql/lib/semmle/code/cpp/security/InvalidPointerDereference/InvalidPointerToDereference.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ private module InvalidPointerToDerefBarrier {
9494
predicate isSource(DataFlow::Node source) { isSource(source, _) }
9595

9696
additional predicate isSink(
97-
DataFlow::Node left, DataFlow::Node right, IRGuardCondition g, int k, boolean testIsTrue
97+
DataFlow::Node small, DataFlow::Node large, IRGuardCondition g, int k, boolean testIsTrue
9898
) {
9999
// The sink is any "large" side of a relational comparison.
100-
g.comparesLt(left.asOperand(), right.asOperand(), k, true, testIsTrue)
100+
g.comparesLt(small.asOperand(), large.asOperand(), k, true, testIsTrue)
101101
}
102102

103103
predicate isSink(DataFlow::Node sink) { isSink(_, sink, _, _, _) }
@@ -106,9 +106,9 @@ private module InvalidPointerToDerefBarrier {
106106
private module BarrierFlow = DataFlow::Global<BarrierConfig>;
107107

108108
/**
109-
* Holds if `g` ensures that `small < big + k` if `g` evaluates to `edge`.
109+
* Holds if `g` ensures that `small < large + k` if `g` evaluates to `edge`.
110110
*
111-
* Additionally, it also holds that `big <= pai`. Thus, when `g` evaluates to `edge`
111+
* Additionally, it also holds that `large <= pai`. Thus, when `g` evaluates to `edge`
112112
* it holds that `small < pai + k`.
113113
*/
114114
private predicate operandGuardChecks(

0 commit comments

Comments
 (0)