Skip to content

Commit

Permalink
Call all Ids id, not idx (#2319)
Browse files Browse the repository at this point in the history
* All Ids should be id not idx

* More

* fix

* win?

* win?

* win?

* fix

* more fix

* desyscall?

* more

* fmt

* std

* make id less id-y

* fmt

* fix

* cleanup

* fixes all around

* fix

* Fix the broken stuff from refactoring

* remove unused

---------

Co-authored-by: Dongjia "toka" Zhang <tokazerkje@outlook.com>
  • Loading branch information
domenukk and tokatoka authored Jun 20, 2024
1 parent a2da080 commit 042840d
Show file tree
Hide file tree
Showing 55 changed files with 508 additions and 486 deletions.
4 changes: 3 additions & 1 deletion fuzzers/baby_fuzzer_minimizing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ pub fn main() -> Result<(), Error> {

state.load_initial_inputs_forced(&mut fuzzer, &mut executor, &mut mgr, &[solution_dir])?;

state.set_corpus_idx(CorpusId::from(0_usize))?;
let first_id = state.corpus().first().expect("Empty corpus");
state.set_corpus_id(first_id)?;

stages.perform_all(&mut fuzzer, &mut executor, &mut state, &mut mgr)?;

Ok(())
Expand Down
13 changes: 10 additions & 3 deletions fuzzers/tutorial/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::hash::Hash;

use lain::prelude::*;
use libafl::inputs::{HasTargetBytes, Input};
use libafl::{
corpus::CorpusId,
inputs::{HasTargetBytes, Input},
};
use libafl_bolts::{ownedref::OwnedSlice, HasLen};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -45,8 +48,12 @@ pub enum PacketType {
}

impl Input for PacketData {
fn generate_name(&self, idx: usize) -> String {
format!("id_{idx}")
fn generate_name(&self, id: Option<CorpusId>) -> String {
if let Some(id) = id {
format!("id_{}", id.0)
} else {
"id_unknown".into()
}
}
}

Expand Down
34 changes: 17 additions & 17 deletions libafl/src/corpus/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ where
fn cache_testcase<'a>(
&'a self,
testcase: &'a RefCell<Testcase<I>>,
idx: CorpusId,
id: CorpusId,
) -> Result<(), Error> {
if testcase.borrow().input().is_none() {
self.load_input_into(&mut testcase.borrow_mut())?;
Expand All @@ -62,7 +62,7 @@ where
}
}
}
self.cached_indexes.borrow_mut().push_back(idx);
self.cached_indexes.borrow_mut().push_back(id);
}
Ok(())
}
Expand Down Expand Up @@ -102,30 +102,30 @@ where

/// Replaces the testcase at the given idx
#[inline]
fn replace(&mut self, idx: CorpusId, testcase: Testcase<I>) -> Result<Testcase<I>, Error> {
fn replace(&mut self, id: CorpusId, testcase: Testcase<I>) -> Result<Testcase<I>, Error> {
// TODO finish
self.inner.replace(idx, testcase)
self.inner.replace(id, testcase)
}

/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases.
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<Self::Input>, Error> {
let testcase = self.inner.remove(idx)?;
self.cached_indexes.borrow_mut().retain(|e| *e != idx);
fn remove(&mut self, id: CorpusId) -> Result<Testcase<Self::Input>, Error> {
let testcase = self.inner.remove(id)?;
self.cached_indexes.borrow_mut().retain(|e| *e != id);
Ok(testcase)
}

/// Get by id; considers only enabled testcases
#[inline]
fn get(&self, idx: CorpusId) -> Result<&RefCell<Testcase<I>>, Error> {
let testcase = { self.inner.get(idx)? };
self.cache_testcase(testcase, idx)?;
fn get(&self, id: CorpusId) -> Result<&RefCell<Testcase<I>>, Error> {
let testcase = { self.inner.get(id)? };
self.cache_testcase(testcase, id)?;
Ok(testcase)
}
/// Get by id; considers both enabled and disabled testcases
#[inline]
fn get_from_all(&self, idx: CorpusId) -> Result<&RefCell<Testcase<Self::Input>>, Error> {
let testcase = { self.inner.get_from_all(idx)? };
self.cache_testcase(testcase, idx)?;
fn get_from_all(&self, id: CorpusId) -> Result<&RefCell<Testcase<Self::Input>>, Error> {
let testcase = { self.inner.get_from_all(id)? };
self.cache_testcase(testcase, id)?;
Ok(testcase)
}

Expand All @@ -142,8 +142,8 @@ where
}

#[inline]
fn next(&self, idx: CorpusId) -> Option<CorpusId> {
self.inner.next(idx)
fn next(&self, id: CorpusId) -> Option<CorpusId> {
self.inner.next(id)
}

/// Peek the next free corpus id
Expand All @@ -153,8 +153,8 @@ where
}

#[inline]
fn prev(&self, idx: CorpusId) -> Option<CorpusId> {
self.inner.prev(idx)
fn prev(&self, id: CorpusId) -> Option<CorpusId> {
self.inner.prev(id)
}

#[inline]
Expand Down
Loading

0 comments on commit 042840d

Please sign in to comment.