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

Implement From LibAFL Error for Qemu Error #2641

Merged
merged 6 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
15 changes: 15 additions & 0 deletions libafl_bolts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ pub enum Error {
Unknown(String, ErrorBacktrace),
/// Error with the corpora
InvalidCorpus(String, ErrorBacktrace),
/// Error specific to a frontend like QEMU or Frida
Frontend(String, ErrorBacktrace),
rmalmain marked this conversation as resolved.
Show resolved Hide resolved
}

impl Error {
Expand Down Expand Up @@ -438,6 +440,15 @@ impl Error {
{
Error::InvalidCorpus(arg.into(), ErrorBacktrace::new())
}

/// Error specific to some frontend, like QEMU or Frida
#[must_use]
pub fn frontend<S>(arg: S) -> Self
where
S: Into<String>,
{
Error::Frontend(arg.into(), ErrorBacktrace::new())
}
}

impl Display for Error {
Expand Down Expand Up @@ -502,6 +513,10 @@ impl Display for Error {
write!(f, "Invalid corpus: {0}", &s)?;
display_error_backtrace(f, b)
}
Self::Frontend(s, b) => {
write!(f, "Frontend error: {0}", &s)?;
display_error_backtrace(f, b)
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions libafl_qemu/src/qemu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ pub enum QemuError {
RW(QemuRWError),
}

impl From<QemuError> for libafl::Error {
fn from(qemu_error: QemuError) -> Self {
libafl::Error::frontend(qemu_error)
}
}

impl From<QemuError> for String {
fn from(qemu_error: QemuError) -> Self {
format!("LibAFL QEMU Error: {qemu_error:?}")
}
}

#[derive(Debug)]
pub enum QemuInitError {
MultipleInstances,
Expand Down
Loading