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

added write_file_atomic against ondisk corpus races #294

Merged
merged 10 commits into from
Sep 13, 2021
Merged

Conversation

domenukk
Copy link
Member

This PR fixes #289 by atomically adding a lockfile before using a filename.
It appends a number to the filename in case of a collision.
Also, it first writes to a tmp file, then moves to the actual filename.
Each of them are dofiles (which should then be ignored for further processing)

@s1341
Copy link
Collaborator

s1341 commented Sep 13, 2021

Perhaps it would make sense to have a safe_write_file utility function. For example, I've implemented a custom input which uses bincode instead of postcard for serialization. I've overriden the to_file trait method, but will want to be able to write my file safely...

@domenukk
Copy link
Member Author

Right now the code is more or less copy and pasted so definitely makes sense. Where should that go? Bolts?

@s1341
Copy link
Collaborator

s1341 commented Sep 13, 2021

I'd imagine bolts file utils or something?

@domenukk
Copy link
Member Author

Added bolts::fs::write_file_atomic

@domenukk domenukk changed the title fix ondisk corpus race condition added write_file_atomic against ondisk corpus races Sep 13, 2021
@s1341
Copy link
Collaborator

s1341 commented Sep 13, 2021

Awesome! Will test this once it is merged.

@domenukk domenukk merged commit 55c4b0c into main Sep 13, 2021
@domenukk domenukk deleted the ondisk_race_fix branch September 14, 2021 12:07
khang06 pushed a commit to khang06/LibAFL that referenced this pull request Oct 11, 2022
* fix ondisk corpus race condition

* move metadata name to be a dotfile

* note ExitKind for crashes and timeouts in inprocess executor

* potential fix for windows

* added write_file_atomic

* no_std fixes

* no_std testcase fix

* typo fix, windows

* clippy

* more no_std testing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants