Skip to content

Commit 48f00f8

Browse files
committed
hot fix for out of bound read to values
1 parent c7611cf commit 48f00f8

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

rapx/src/analysis/safedrop/alias.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
127127
// assign to the variable _x, we will set the birth of _x and its child self.values a new birth.
128128
pub fn fill_birth(&mut self, node: usize, birth: isize) {
129129
self.values[node].birth = birth;
130-
for i in 0..self.alias_set.len() {
130+
for i in 0..self.values.len() {
131131
if self.union_is_same(i, node) && self.values[i].birth == -1 {
132132
self.values[i].birth = birth;
133133
}
@@ -172,7 +172,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
172172
node.birth = self.values[proj_id].birth;
173173
node.field_id = field_idx;
174174
self.values[proj_id].fields.insert(field_idx, node.index);
175-
self.alias_set.push(self.values.len());
175+
self.alias_set.push(self.alias_set.len());
176176
self.dead_record.push(false);
177177
self.values.push(node);
178178
}
@@ -206,7 +206,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
206206
node.birth = self.values[lv].birth;
207207
node.field_id = field.0;
208208
self.values[lv].fields.insert(field.0, node.index);
209-
self.alias_set.push(self.values.len());
209+
self.alias_set.push(self.alias_set.len());
210210
self.dead_record.push(false);
211211
self.values.push(node);
212212
}
@@ -234,7 +234,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
234234
node.birth = self.values[lv].birth;
235235
node.field_id = *index;
236236
self.values[lv].fields.insert(*index, node.index);
237-
self.alias_set.push(self.values.len());
237+
self.alias_set.push(self.alias_set.len());
238238
self.dead_record.push(false);
239239
self.values.push(node);
240240
}
@@ -249,7 +249,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
249249
if !self.values[rv].fields.contains_key(&index) {
250250
let need_drop = ret_alias.right_need_drop;
251251
let may_drop = ret_alias.right_may_drop;
252-
let mut node = ValueNode::new(self.values.len(), right_init, need_drop, may_drop);
252+
let mut node = ValueNode::new(self.alias_set.len(), right_init, need_drop, may_drop);
253253
node.kind = TyKind::RawPtr;
254254
node.birth = self.values[rv].birth;
255255
node.field_id = *index;
@@ -263,7 +263,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
263263
self.merge_alias(lv, rv);
264264
}
265265

266-
#[inline]
266+
#[inline(always)]
267267
pub fn union_find(&mut self, e: usize) -> usize {
268268
let mut r = e;
269269
while self.alias_set[r] != r {
@@ -272,7 +272,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
272272
r
273273
}
274274

275-
#[inline]
275+
#[inline(always)]
276276
pub fn union_merge(&mut self, e1: usize, e2: usize) {
277277
let f1 = self.union_find(e1);
278278
let f2 = self.union_find(e2);
@@ -289,13 +289,14 @@ impl<'tcx> SafeDropGraph<'tcx> {
289289
}
290290
}
291291

292-
#[inline]
292+
#[inline(always)]
293293
pub fn union_is_same(&mut self, e1: usize, e2: usize) -> bool {
294294
let f1 = self.union_find(e1);
295295
let f2 = self.union_find(e2);
296296
f1 == f2
297297
}
298298

299+
#[inline(always)]
299300
pub fn union_has_alias(&mut self, e: usize) -> bool {
300301
for i in 0..self.alias_set.len() {
301302
if i == e {

rapx/src/analysis/safedrop/check_bugs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
4747
record: &mut FxHashSet<usize>,
4848
dangling: bool,
4949
) -> bool {
50+
if node>= self.values.len() { return false; }
5051
//if is a dangling pointer check, only check the pointer type varible.
5152
if self.values[node].is_alive() == false
5253
&& (dangling && self.values[node].is_ptr() || !dangling)
@@ -138,7 +139,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
138139
// }
139140
// self.dead_node(i, birth, info, true);
140141
// }
141-
for i in 0..self.alias_set.len() {
142+
for i in 0..self.values.len() {
142143
if !self.union_is_same(drop, i) || i == drop || self.values[i].is_ref() {
143144
continue;
144145
}

rapx/src/analysis/safedrop/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
208208
need_drop || may_drop,
209209
);
210210
node.kind = kind(local_decl.ty);
211-
alias.push(values.len());
211+
alias.push(alias.len());
212212
dead.push(false);
213213
values.push(node);
214214
}
@@ -295,7 +295,7 @@ impl<'tcx> SafeDropGraph<'tcx> {
295295
lvl0.birth = values[lv_local].birth;
296296
lvl0.field_id = 0;
297297
values[lv_local].fields.insert(0, lvl0.index);
298-
alias.push(values.len());
298+
alias.push(alias.len());
299299
dead.push(false);
300300
values.push(lvl0);
301301
}

0 commit comments

Comments
 (0)