-
-
Notifications
You must be signed in to change notification settings - Fork 292
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 testcase set_filename #1092
Conversation
libafl/src/corpus/testcase.rs
Outdated
self.filename = Some(filename); | ||
|
||
match self.store_input() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we store, do we want to remove the old version (if that exists)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove old file versions, we could implement a delete function for the Input trait.
But I'm wondering why this issue is even a problem on the first place?
Isn't set_filename
is only called when testcase.filename
does not exist? Hence it is impossible to have self.filename with some string value.
@VTCAKAVSMoACE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the solution here is to check if the file .<filename>.lafl_lock
exists. If it does not, then it is safe to remove. Otherwise, return an illegal state error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe in this case, we also must not simply store_input
but actually to move the input file, the .metadata file, and the .lafl_lock (if each exist). Otherwise, this will simply create a copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't we maybe have created the lock file, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we would have made the lockfile. But even so, if we are renaming to something that we currently use, it would be unsafe to remove/replace the destination file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added rename file logic. If either old lock file or new lock file exist, then set_filename will return error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will that ever work, then? When is the lock file removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added some more code to the functions.
So the idea is that old/new lock files are created and deleted in set_filename function.
If lock file are already created for old/new testcase then set_filename called, then it throws an error.
By doing this testcases could be safely created and removed.
libafl/src/corpus/testcase.rs
Outdated
@@ -4,6 +4,9 @@ | |||
use alloc::string::String; | |||
use core::{default::Default, option::Option, time::Duration}; | |||
|
|||
#[cfg(feature = "std")] | |||
use std::{fs, path::Path}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay for testcase.rs to depend on std?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs to work without (for inmemory), but for storing to disk it needs std yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added set_Filename function for no_std.
Since there is no file creation/deletion, it just assigns value to struct.
clippy complains error: the borrowed expression implements the required traits
--> libafl/src/corpus/testcase.rs:176:24
|
176 | fs::rename(&old_filename, &new_filename)?;
| ^^^^^^^^^^^^^ help: change this to: `old_filename`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
note: the lint level is defined here
--> libafl/src/lib.rs:16:9
|
16 | #![deny(clippy::all)]
| ^^^^^^^^^^^
= note: `#[deny(clippy::needless_borrow)]` implied by `#[deny(clippy::all)]`
error: the borrowed expression implements the required traits
--> libafl/src/corpus/testcase.rs:176:39
|
176 | fs::rename(&old_filename, &new_filename)?;
| ^^^^^^^^^^^^^ help: change this to: `new_filename`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: the borrowed expression implements the required traits
--> libafl/src/corpus/testcase.rs:180:24
|
180 | fs::rename(&old_metadata_filename, &new_metadata_filename)?;
| ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `old_metadata_filename`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
error: the borrowed expression implements the required traits
--> libafl/src/corpus/testcase.rs:180:48
|
180 | fs::rename(&old_metadata_filename, &new_metadata_filename)?;
| ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `new_metadata_filename`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow |
fixed |
@addisoncrump do you think this is correct now? thx :) |
Sorry, missed the update. Looks good to me now, thanks! 👍 |
Fix testcase set_filename (AFLplusplus#1092)
fuzzbench_qemu broken after this |
@SpaceWhite can you check this again? |
@tokatoka Sorry for the long wait. I just sent the PR to fix this. |
fix #1084
add rename file logic in set_filename when new file name is set