-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sanity check on output directory and avoid duplicated minimal f…
…ile to get overwritten
- Loading branch information
Showing
1 changed file
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,7 +292,18 @@ def setup_argparse(): | |
) | ||
return parser.parse_args() | ||
|
||
|
||
def do_unique_copy(filepath, dest_path): | ||
filename = os.path.basename(filepath) | ||
new_dest = os.path.join(dest_path, filename) | ||
|
||
id = 0 | ||
# Avoid duplicated filename in the destination folder | ||
while os.path.exists(new_dest): | ||
new_dest = os.path.join(dest_path, filename+"_"+str(id)) | ||
|
||
# Now we can copy the file to destination | ||
shutil.copy(filepath, new_dest) | ||
|
||
def main(argc, argv): | ||
print 'corpus minimization tool for WinAFL by <[email protected]>' | ||
print 'Based on WinAFL by <[email protected]>' | ||
|
@@ -324,6 +335,13 @@ def main(argc, argv): | |
) | ||
return 1 | ||
|
||
# Another sanity check on the root of output directory | ||
if os.path.isdir(os.path.split(args.output)[0]) is False: | ||
logging.error( | ||
'[!] The output directory %r is not a directory', args.output | ||
) | ||
return 1 | ||
|
||
if os.path.isdir(args.working_dir) is False: | ||
logging.error( | ||
'[!] The working directory %r is not a directory', args.working_dir | ||
|
@@ -644,7 +662,7 @@ def main(argc, argv): | |
) | ||
os.mkdir(args.output) | ||
for file_path in minset: | ||
shutil.copy(file_path, args.output) | ||
do_unique_copy(file_path, args.output) | ||
|
||
logging.info('[+] Time elapsed: %d seconds', time.time() - t0) | ||
return 0 | ||
|