Skip to content

Commit

Permalink
chore: remove unsafe code.
Browse files Browse the repository at this point in the history
This may be causing a heap corruption, due to `rule_id` being out of range. By removing the unsafe code we can debug the issue better.
  • Loading branch information
plusvic committed Oct 28, 2024
1 parent 8140408 commit 329f5e5
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions lib/src/scanner/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,13 @@ impl ScanContext<'_> {
/// increased by the time elapsed since `rule_execution_start_time`.
#[cfg(feature = "rules-profiling")]
pub(crate) fn update_time_spent_in_rule(&mut self, rule_id: RuleId) {
// SAFETY: it's safe to call `get_unchecked_mut`, the size of the
// `time_spent_in_rule` vector is guaranteed to be the number of
// existing rules. Therefore, the rule ID can be used as an index
// in this vector.
unsafe {
self.time_spent_in_rule
.get_unchecked_mut::<usize>(rule_id.into())
.add_assign(self.clock.delta_as_nanos(
self.rule_execution_start_time,
self.clock.raw(),
));
}
self.time_spent_in_rule
.get_mut::<usize>(rule_id.into())
.unwrap()
.add_assign(self.clock.delta_as_nanos(
self.rule_execution_start_time,
self.clock.raw(),
));
}

/// Called during the scan process when a rule didn't match.
Expand Down

0 comments on commit 329f5e5

Please sign in to comment.