Skip to content

libafl_qemu: Returning errors in snapshots on saving and loading #3764

Open
Tanmay140906 wants to merge 2 commits intoAFLplusplus:mainfrom
Tanmay140906:libafl_snapshot_qemu
Open

libafl_qemu: Returning errors in snapshots on saving and loading #3764
Tanmay140906 wants to merge 2 commits intoAFLplusplus:mainfrom
Tanmay140906:libafl_snapshot_qemu

Conversation

@Tanmay140906
Copy link
Copy Markdown
Contributor

@Tanmay140906 Tanmay140906 commented Mar 22, 2026

Description

This PR propagates snapshot errors from QEMU to Rust by:

  • Changing libafl_save_qemu_snapshot and libafl_load_qemu_snapshot to return int
  • Returning -1 on failure and 0 on success
  • Updating Rust bindings to return Result<(), QemuSnapshotError>
  • Allowing users to handle snapshot failures explicitly

Async snapshot mode failure reports need to be handled yet.

Fixes #1512

Since the qemu_snapshot file and it's functions are generated during build time, these are the recommended changes to make so that this causes no code to break and works fine:

Changes

1. libafl/qemu_snapshot.c

-int libafl_save_qemu_snapshot(char* name, bool sync)
+int libafl_save_qemu_snapshot(char* name, bool sync)
 {
     ...
-        if (!save_snapshot(name, true, NULL, false, NULL, &err)) {
+        if (!save_snapshot(name, true, NULL, false, NULL, &err)) {
             error_report_err(err);
             error_report("Could not save snapshot");
-            return;
+            return -1;
         }
-        return;
+        return 0;
     }
     ...
-    return;
+    return 0;
 }

-int libafl_load_qemu_snapshot(char* name, bool sync)
+int libafl_load_qemu_snapshot(char* name, bool sync)
 {
     ...
-        if (!loaded) {
+        if (!loaded) {
             error_report_err(err);
             error_report("Could not load snapshot");
-            return;
+            return -1;
         }
         ...
-        return;
+        return 0;
     }
     ...
-    return;
+    return 0;
 }
  1. libafl/qemu_snapshot.h
-void libafl_save_qemu_snapshot(char* name, bool sync);
-void libafl_load_qemu_snapshot(char* name, bool sync);
+int libafl_save_qemu_snapshot(char* name, bool sync);
+int libafl_load_qemu_snapshot(char* name, bool sync);

Checklist

  • I have run ./scripts/precommit.sh and addressed all comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libafl_qemu: Return errors from libafl_save_qemu_snapshot, Emulator::save_snapshot

1 participant