From 329f5e5c91ee3e92cb44c681c368ba5beba4f085 Mon Sep 17 00:00:00 2001 From: "Victor M. Alvarez" Date: Mon, 28 Oct 2024 19:08:21 +0100 Subject: [PATCH] chore: remove unsafe code. 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. --- lib/src/scanner/context.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/src/scanner/context.rs b/lib/src/scanner/context.rs index 1377913d..37f0fee9 100644 --- a/lib/src/scanner/context.rs +++ b/lib/src/scanner/context.rs @@ -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::(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::(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.