From 3dfdba2ddc0774baedb9bab52c11209839da7d38 Mon Sep 17 00:00:00 2001 From: Dongjia Zhang Date: Fri, 5 Aug 2022 09:05:15 +0200 Subject: [PATCH] Resize MapFeedbackMetadata with observer.initial() (#718) --- libafl/src/feedbacks/map.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libafl/src/feedbacks/map.rs b/libafl/src/feedbacks/map.rs index bb749c3579..fb137cc38e 100644 --- a/libafl/src/feedbacks/map.rs +++ b/libafl/src/feedbacks/map.rs @@ -314,6 +314,15 @@ where } Ok(()) } + + /// Reset the map with any value + pub fn reset_with_value(&mut self, value: T) -> Result<(), Error> { + let cnt = self.history_map.len(); + for i in 0..cnt { + self.history_map[i] = value; + } + Ok(()) + } } /// The most common AFL-like feedback type @@ -352,6 +361,8 @@ where S: HasNamedMetadata + HasClientPerfMonitor + Debug, { fn init_state(&mut self, state: &mut S) -> Result<(), Error> { + // Initialize `MapFeedbackMetadata` with an empty vector and add it to the state. + // The `MapFeedbackMetadata` would be resized on-demand in `is_interesting` state.add_named_metadata(MapFeedbackMetadata::::default(), &self.name); Ok(()) } @@ -659,7 +670,7 @@ where .unwrap(); let len = observer.len(); if map_state.history_map.len() < len { - map_state.history_map.resize(len, T::default()); + map_state.history_map.resize(len, observer.initial()); } let history_map = map_state.history_map.as_mut_slice();