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

Fix #1932 #2089

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion fuzzers/frida_libpng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ reqwest = { version = "0.11.4", features = ["blocking"] }


[dependencies]
libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public", "frida_cli" ] } #, "llmp_small_maps", "llmp_debug"]}
libafl = { path = "../../libafl/", features = [ "std", "llmp_compression", "llmp_bind_public", "frida_cli", "errors_backtrace" ] } #, "llmp_small_maps", "llmp_debug"]}
libafl_bolts = { path = "../../libafl_bolts/" }
frida-gum = { version = "0.13.6", features = [ "auto-download", "event-sink", "invocation-listener"] }
libafl_frida = { path = "../../libafl_frida", features = ["cmplog"] }
Expand Down
2 changes: 1 addition & 1 deletion fuzzers/frida_libpng/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ script_runner = "@shell"
script='''
rm -rf libafl_unix_shmem_server || true
timeout 30s ./${FUZZER_NAME} -F LLVMFuzzerTestOneInput -H ./libpng-harness.so -l ./libpng-harness.so | tee fuzz_stdout.log 2>/dev/null || true
if grep -qa "corpus: 30" fuzz_stdout.log; then
if grep -qa "corpus: 70" fuzz_stdout.log; then
echo "Fuzzer is working"
else
echo "Fuzzer does not generate any testcases or any crashes"
Expand Down
6 changes: 3 additions & 3 deletions fuzzers/frida_libpng/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ unsafe fn fuzz(options: &FuzzerOptions) -> Result<(), Error> {
// RNG
StdRand::with_seed(current_nanos()),
// Corpus that will be evolved, we keep it in memory for performance
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 64)
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an example fuzzer this might be a bit small?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that was for debugging
i forgot to remove

.unwrap(),
// Corpus in which we store solutions (crashes in this example),
// on disk so the user can get them after stopping the fuzzer
Expand Down Expand Up @@ -256,7 +256,7 @@ unsafe fn fuzz(options: &FuzzerOptions) -> Result<(), Error> {
// RNG
StdRand::with_seed(current_nanos()),
// Corpus that will be evolved, we keep it in memory for performance
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 64)
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 4)
.unwrap(),
// Corpus in which we store solutions (crashes in this example),
// on disk so the user can get them after stopping the fuzzer
Expand Down Expand Up @@ -386,7 +386,7 @@ unsafe fn fuzz(options: &FuzzerOptions) -> Result<(), Error> {
// RNG
StdRand::with_seed(current_nanos()),
// Corpus that will be evolved, we keep it in memory for performance
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 64)
CachedOnDiskCorpus::no_meta(PathBuf::from("./corpus_discovered"), 4)
.unwrap(),
// Corpus in which we store solutions (crashes in this example),
// on disk so the user can get them after stopping the fuzzer
Expand Down
14 changes: 4 additions & 10 deletions libafl/src/corpus/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,14 @@ where
&'a self,
testcase: &'a RefCell<Testcase<I>>,
idx: CorpusId,
is_disabled: bool,
) -> Result<(), Error> {
if testcase.borrow().input().is_none() {
self.load_input_into(&mut testcase.borrow_mut())?;
let mut borrowed_num = 0;
while self.cached_indexes.borrow().len() >= self.cache_max_len {
let removed = self.cached_indexes.borrow_mut().pop_front().unwrap();
if let Ok(mut borrowed) = if is_disabled {
self.inner.get_from_all(removed)
} else {
self.inner.get(removed)
}?
.try_borrow_mut()
{

if let Ok(mut borrowed) = self.inner.get_from_all(removed)?.try_borrow_mut() {
*borrowed.input_mut() = None;
} else {
self.cached_indexes.borrow_mut().push_back(removed);
Expand Down Expand Up @@ -125,14 +119,14 @@ where
#[inline]
fn get(&self, idx: CorpusId) -> Result<&RefCell<Testcase<I>>, Error> {
let testcase = { self.inner.get(idx)? };
self.cache_testcase(testcase, idx, false)?;
self.cache_testcase(testcase, idx)?;
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> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we even cache if the testcase is disabled? I don't know if we usually want that, it should be used way less?

let testcase = { self.inner.get_from_all(idx)? };
self.cache_testcase(testcase, idx, true)?;
self.cache_testcase(testcase, idx)?;
Ok(testcase)
}

Expand Down
2 changes: 1 addition & 1 deletion libafl_bolts/src/os/unix_signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ use crate::Error;

extern "C" {
/// The `libc` `getcontext`
/// For some reason, it's not available on MacOS.
/// For some reason, it's not available on `MacOS`.
///
fn getcontext(ucp: *mut ucontext_t) -> c_int;
}
Expand Down
2 changes: 1 addition & 1 deletion libafl_cc/src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl ToolWrapper for ClangWrapper {
if linking {
new_args.push("-lrt".into());
}
// MacOS has odd linker behavior sometimes
// `MacOS` has odd linker behavior sometimes
#[cfg(target_vendor = "apple")]
if linking || shared {
new_args.push("-undefined".into());
Expand Down
Loading