Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove_from_all method to Corpus trait #2259

Merged
merged 5 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions libafl/src/corpus/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ where
self.inner.replace(idx, testcase)
}

/// Removes an entry from the corpus, returning it if it was present.
#[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
/// 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);
Ok(testcase)
Expand Down
12 changes: 7 additions & 5 deletions libafl/src/corpus/inmemory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,14 @@ where
.ok_or_else(|| Error::key_not_found(format!("Index {idx} not found")))
}

/// Removes an entry from the corpus, returning it if it was present.
/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
self.storage
.enabled
.remove(idx)
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<Self::Input>, Error> {
let mut testcase = self.storage.enabled.remove(idx);
if testcase.is_none() {
testcase = self.storage.disabled.remove(idx);
}
testcase
.map(|x| x.take())
.ok_or_else(|| Error::key_not_found(format!("Index {idx} not found")))
}
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/corpus/inmemory_ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
Ok(entry)
}

/// Removes an entry from the corpus, returning it if it was present.
/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled corpus
#[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
let entry = self.inner.remove(idx)?;
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/corpus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub trait Corpus: UsesInput + Serialize + for<'de> Deserialize<'de> {
testcase: Testcase<Self::Input>,
) -> Result<Testcase<Self::Input>, Error>;

/// Removes an entry from the corpus, returning it if it was present.
/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
fn remove(&mut self, id: CorpusId) -> Result<Testcase<Self::Input>, Error>;

/// Get by id; considers only enabled testcases
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/corpus/nop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
Err(Error::unsupported("Unsupported by NopCorpus"))
}

/// Removes an entry from the corpus, returning it if it was present.
/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline]
fn remove(&mut self, _idx: CorpusId) -> Result<Testcase<I>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus"))
Expand Down
2 changes: 1 addition & 1 deletion libafl/src/corpus/ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
self.inner.peek_free_id()
}

/// Removes an entry from the corpus, returning it if it was present.
/// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
self.inner.remove(idx)
Expand Down
Loading