Skip to main content

rapx/check/safedrop/
observer.rs

1use rustc_span::Span;
2
3use crate::analysis::alias::default::graph::AliasGraph;
4use crate::analysis::alias::observer::AliasObserver;
5
6use super::bug_records::*;
7use super::checks;
8use super::drop::DropRecord;
9
10pub struct SafeDropObserver<'a> {
11    pub drop_record: &'a mut Vec<DropRecord>,
12    pub bug_records: &'a mut BugRecords,
13    pub current_bb: usize,
14}
15
16impl AliasObserver for SafeDropObserver<'_> {
17    fn on_value_use(&mut self, graph: &AliasGraph, vidx: usize, span: Span, in_call: bool) {
18        checks::sync_drop_record(graph, self.drop_record);
19        checks::uaf_check(
20            graph,
21            self.drop_record,
22            self.bug_records,
23            vidx,
24            self.current_bb,
25            span,
26            in_call,
27        );
28    }
29
30    fn on_value_assign(&mut self, graph: &AliasGraph, vidx: usize) {
31        checks::sync_drop_record(graph, self.drop_record);
32        checks::clear_drop_info(graph, self.drop_record, vidx);
33    }
34
35    fn on_state_change(&mut self, graph: &AliasGraph) {
36        checks::sync_drop_record(graph, self.drop_record);
37    }
38}