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 drcov path parsing #2884

Merged
merged 31 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from 20 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
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,15 @@ z3 = "0.12.1"


[workspace.lints.rust]
# Deny
warnings = { level = "deny", priority = -1 }

# Forbid
unexpected_cfgs = "forbid"

# Allow
incomplete_features = "allow"
ambiguous_glob_reexports = "allow"
# ambiguous_glob_reexports = "allow"


[workspace.lints.clippy]
Expand All @@ -142,9 +145,10 @@ cargo_common_metadata = "deny"

# Warn
cargo = { level = "warn", priority = -1 }
negative_feature_names = "warn"

# Allow
negative_feature_names = "allow" # TODO: turn into 'warn' when working
multiple_crate_versions = "allow" # TODO: turn into `warn` when working
unreadable_literal = "allow"
type_repetition_in_bounds = "allow"
missing_errors_doc = "allow"
Expand Down
6 changes: 4 additions & 2 deletions bindings/pylibafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ pyo3-build-config = { workspace = true }
name = "pylibafl"
crate-type = ["cdylib"]

[profile.dev]
panic = "abort"
# TODO: find a way to fix this when a solution is found
# https://github.com/rust-lang/cargo/issues/9330
# [profile.dev]
# panic = "abort"
8 changes: 4 additions & 4 deletions fuzzers/binary_only/qemu_coverage/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ windows_alias = "unsupported"
command = "${TARGET_DIR}/${PROFILE_DIR}/qemu_coverage-${CARGO_MAKE_PROFILE}"
args = [
"--coverage-path",
"${TARGET_DIR}/drcov.log",
"${TARGET_DIR}/cov.drcov",
"--input-dir",
"./corpus",
"--",
Expand Down Expand Up @@ -294,11 +294,11 @@ script = '''
cargo make ${FEATURE} || exit 1

cargo run --manifest-path ../../../utils/drcov_utils/Cargo.toml --bin drcov_merge -- \
-i ${TARGET_DIR}/drcov-000.log ${TARGET_DIR}/drcov-001.log ${TARGET_DIR}/drcov-002.log ${TARGET_DIR}/drcov-003.log \
--output ${TARGET_DIR}/drcov-merged.log || exit 1
-i ${TARGET_DIR}/cov-000.drcov ${TARGET_DIR}/cov-001.drcov ${TARGET_DIR}/cov-002.drcov ${TARGET_DIR}/cov-003.drcov \
--output ${TARGET_DIR}/cov-merged.drcov || exit 1

TMP=$(cargo run --manifest-path ../../../utils/drcov_utils/Cargo.toml --bin drcov_dump_addrs -- \
-i ${TARGET_DIR}/drcov-merged.log | wc -l || exit 1)
-i ${TARGET_DIR}/cov-merged.drcov | wc -l || exit 1)

NB_BLOCKS=$((TMP - 1))

Expand Down
5 changes: 1 addition & 4 deletions fuzzers/binary_only/qemu_coverage/src/fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,7 @@ pub fn fuzz() {
cov_path.set_file_name(format!("{coverage_name}-{core:03}.{coverage_extension}"));

let emulator_modules = tuple_list!(
DrCovModule::builder()
.filename(cov_path.clone())
.full_trace(false)
.build(),
DrCovModule::builder().filename(cov_path.clone()).build(),
SnapshotModule::new()
);

Expand Down
2 changes: 2 additions & 0 deletions libafl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub use libafl_bolts::{nonzero, Error};
/// The purpose of this module is to alleviate imports of many components by adding a glob import.
#[cfg(feature = "prelude")]
pub mod prelude {
#![allow(ambiguous_glob_reexports)]
rmalmain marked this conversation as resolved.
Show resolved Hide resolved

pub use super::{
corpus::*, events::*, executors::*, feedbacks::*, fuzzer::*, generators::*, inputs::*,
monitors::*, mutators::*, observers::*, schedulers::*, stages::*, state::*, *,
Expand Down
2 changes: 2 additions & 0 deletions libafl_bolts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ impl From<pyo3::PyErr> for Error {
/// The purpose of this module is to alleviate imports of many components by adding a glob import.
#[cfg(feature = "prelude")]
pub mod prelude {
#![allow(ambiguous_glob_reexports)]
rmalmain marked this conversation as resolved.
Show resolved Hide resolved

pub use super::{bolts_prelude::*, *};
}

Expand Down
9 changes: 3 additions & 6 deletions libafl_bolts/src/tuples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#[cfg(feature = "alloc")]
use alloc::{borrow::Cow, vec::Vec};
#[cfg(feature = "alloc")]
use core::ops::{Deref, DerefMut};
use core::{
any::{type_name, TypeId},
cell::Cell,
any::type_name,
fmt::{Debug, Formatter},
marker::PhantomData,
mem::transmute,
ops::{Index, IndexMut},
ops::{Deref, DerefMut, Index, IndexMut},
};
use core::{any::TypeId, cell::Cell, marker::PhantomData, mem::transmute};

#[cfg(feature = "alloc")]
use serde::{Deserialize, Serialize};
Expand Down
44 changes: 36 additions & 8 deletions libafl_cc/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
use std::{
env,
fs::File,
io::Write,
path::{Path, PathBuf},
process::Command,
str,
};
#[cfg(any(
target_vendor = "apple",
feature = "ddg-instr",
feature = "function-logging",
feature = "cmplog-routines",
feature = "autotokens",
feature = "coverage-accounting",
feature = "cmplog-instructions",
feature = "ctx",
feature = "dump-cfg",
feature = "profiling",
))]
use std::path::PathBuf;
use std::{env, fs::File, io::Write, path::Path, process::Command, str};

#[cfg(target_vendor = "apple")]
use glob::glob;
Expand All @@ -20,6 +26,17 @@ const LLVM_VERSION_MAX: u32 = 33;
const LLVM_VERSION_MIN: u32 = 6;

/// Get the extension for a shared object
#[cfg(any(
feature = "ddg-instr",
feature = "function-logging",
feature = "cmplog-routines",
feature = "autotokens",
feature = "coverage-accounting",
feature = "cmplog-instructions",
feature = "ctx",
feature = "dump-cfg",
feature = "profiling",
))]
fn dll_extension<'a>() -> &'a str {
if let Ok(vendor) = env::var("CARGO_CFG_TARGET_VENDOR") {
if vendor == "apple" {
Expand Down Expand Up @@ -143,6 +160,17 @@ fn find_llvm_version() -> Option<i32> {
None
}

#[cfg(any(
feature = "ddg-instr",
feature = "function-logging",
feature = "cmplog-routines",
feature = "autotokens",
feature = "coverage-accounting",
feature = "cmplog-instructions",
feature = "ctx",
feature = "dump-cfg",
feature = "profiling",
))]
#[expect(clippy::too_many_arguments)]
fn build_pass(
bindir_path: &Path,
Expand Down
2 changes: 2 additions & 0 deletions libafl_concolic/symcc_runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub mod cpp_runtime {
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused_attributes)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

Expand Down
1 change: 1 addition & 0 deletions libafl_concolic/symcc_runtime/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Tracing of expressions in a serialized form.
#![allow(no_mangle_generic_items)]

pub use libafl::observers::concolic::serialization_format::StdShMemMessageFileWriter;
use libafl::observers::concolic::SymExpr;
Expand Down
4 changes: 2 additions & 2 deletions libafl_intelpt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use arbitrary_int::u4;
use bitbybit::bitfield;
#[cfg(target_os = "linux")]
use caps::{CapSet, Capability};
use libafl_bolts::Error;
#[cfg(target_os = "linux")]
use libafl_bolts::ownedref::OwnedRefMut;
use libafl_bolts::{hash_64_fast, Error};
use libafl_bolts::{hash_64_fast, ownedref::OwnedRefMut};
use libipt::PtError;
#[cfg(target_os = "linux")]
use libipt::{
Expand Down
55 changes: 29 additions & 26 deletions libafl_libfuzzer/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,36 +102,39 @@ fn main() -> Result<(), Box<dyn Error>> {
{
todo!("copy all the source files"); // we don't support libafl_libfuzzer for others rn
}
let mut template: toml::Value =
toml::from_str(&fs::read_to_string("runtime/Cargo.toml.template")?)?;
let toml::Value::Table(root) = &mut template else {
unreachable!("Invalid Cargo.toml");
};
root.insert(
"workspace".to_string(),
toml::Value::Table(toml::Table::new()),
);
let Some(toml::Value::Table(deps)) = root.get_mut("dependencies") else {
unreachable!("Invalid Cargo.toml");
};
let version = env!("CARGO_PKG_VERSION");
for (_name, spec) in deps {
if let toml::Value::Table(spec) = spec {
// replace all path deps with version deps
if spec.remove("path").is_some() {
spec.insert(
"version".to_string(),
toml::Value::String(version.to_string()),
);
#[cfg(unix)]
{
let mut template: toml::Value =
toml::from_str(&fs::read_to_string("runtime/Cargo.toml.template")?)?;
let toml::Value::Table(root) = &mut template else {
unreachable!("Invalid Cargo.toml");
};
root.insert(
"workspace".to_string(),
toml::Value::Table(toml::Table::new()),
);
let Some(toml::Value::Table(deps)) = root.get_mut("dependencies") else {
unreachable!("Invalid Cargo.toml");
};
let version = env!("CARGO_PKG_VERSION");
for (_name, spec) in deps {
if let toml::Value::Table(spec) = spec {
// replace all path deps with version deps
if spec.remove("path").is_some() {
spec.insert(
"version".to_string(),
toml::Value::String(version.to_string()),
);
}
}
}
}

let serialized = toml::to_string(&template)?;
fs::write(custom_lib_dir.join("Cargo.toml"), serialized)?;
let serialized = toml::to_string(&template)?;
fs::write(custom_lib_dir.join("Cargo.toml"), serialized)?;

// build in this filled out template
command.current_dir(custom_lib_dir);
// build in this filled out template
command.current_dir(custom_lib_dir);
}
}

assert!(
Expand Down
4 changes: 3 additions & 1 deletion libafl_qemu/build_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ pub fn build() {
let cross_cc = if cfg!(feature = "usermode") && (qemu_asan || qemu_asan_guest) {
// TODO try to autodetect a cross compiler with the arch name (e.g. aarch64-linux-gnu-gcc)
let cross_cc = env::var("CROSS_CC").unwrap_or_else(|_| {
println!("cargo:warning=CROSS_CC is not set, default to cc (things can go wrong if the selected cpu target ({cpu_target}) is not the host arch ({}))", env::consts::ARCH);
if cpu_target != env::consts::ARCH {
println!("cargo:warning=CROSS_CC is not set, default to cc (things can go wrong since the selected cpu target ({cpu_target}) is different from the host arch ({}))", env::consts::ARCH);
}
"cc".to_owned()
});
println!("cargo:rerun-if-env-changed=CROSS_CC");
Expand Down
1 change: 0 additions & 1 deletion libafl_qemu/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ pub type QemuInProcessForkExecutor<'a, C, CM, ED, EM, ET, H, I, OT, S, SM, SP, Z
StatefulInProcessForkExecutor<'a, EM, Emulator<C, CM, ED, ET, I, S, SM>, H, I, OT, S, SP, Z>;

#[cfg(feature = "fork")]
#[expect(clippy::type_complexity)]
pub struct QemuForkExecutor<'a, C, CM, ED, EM, ET, H, I, OT, S, SM, SP, Z> {
inner: QemuInProcessForkExecutor<'a, C, CM, ED, EM, ET, H, I, OT, S, SM, SP, Z>,
}
Expand Down
Loading
Loading