Do not delete existing things - AFLs filenames are unique, so the files are identical anyway

This commit is contained in:
maride 2021-04-22 19:55:12 +02:00
parent 0e10cbdb94
commit 762dfa9ea5

View File

@ -43,14 +43,18 @@ func UnpackInto(raw []byte, targetDir string) error {
if strings.Contains(fuzzerName, "/") { if strings.Contains(fuzzerName, "/") {
return fmt.Errorf("received file name with a slash, discarding whole packet for fuzzer \"%s\"", fuzzerName) return fmt.Errorf("received file name with a slash, discarding whole packet for fuzzer \"%s\"", fuzzerName)
} }
targetDir = fmt.Sprintf("%s%c%s", targetDir, os.PathSeparator, fuzzerName)
// Remove old target directory, and create a new one // Check if our target directory (this very fuzzers directory) already exists, or if we need to create it
targetDir = fmt.Sprintf("%s%c%s", targetDir, os.PathSeparator, fuzzerName)
_, folderErr := os.Stat(targetDir)
if os.IsNotExist(folderErr) {
// directory doesn't yet exist, create it
mkdirErr := os.MkdirAll(targetDir, 0700) mkdirErr := os.MkdirAll(targetDir, 0700)
if mkdirErr != nil { if mkdirErr != nil {
// Creating the target directory failed, so we won't proceed unpacking into a non-existent directory // Creating the target directory failed, so we won't proceed unpacking into a non-existent directory
return fmt.Errorf("unable to unpack packet: could not create directory at %s: %s", targetDir, mkdirErr) return fmt.Errorf("unable to unpack packet: could not create directory at %s: %s", targetDir, mkdirErr)
} }
}
// Process every single part // Process every single part
unpackSingleFile(splitted[1], targetDir, "fuzz_bitmap") unpackSingleFile(splitted[1], targetDir, "fuzz_bitmap")
@ -63,6 +67,14 @@ func UnpackInto(raw []byte, targetDir string) error {
// Writes the contents to the target // Writes the contents to the target
func unpackSingleFile(raw []byte, targetDirectory string, filename string) { func unpackSingleFile(raw []byte, targetDirectory string, filename string) {
path := fmt.Sprintf("%s%c%s", targetDirectory, os.PathSeparator, filename) path := fmt.Sprintf("%s%c%s", targetDirectory, os.PathSeparator, filename)
// Check if the file already exists - we won't overwrite it then
_, fileInfoErr := os.Stat(path)
if os.IsExist(fileInfoErr) {
// File already exists, we don't need to write a thing
return
}
writeErr := ioutil.WriteFile(path, raw, 0644) writeErr := ioutil.WriteFile(path, raw, 0644)
if writeErr != nil { if writeErr != nil {
log.Printf("Unable to write to file %s: %s", path, writeErr) log.Printf("Unable to write to file %s: %s", path, writeErr)
@ -79,9 +91,11 @@ func unpackQueueDir(raw []byte, targetDir string) {
// Set correct path for files // Set correct path for files
targetDir = fmt.Sprintf("%s%cqueue", targetDir, os.PathSeparator) targetDir = fmt.Sprintf("%s%cqueue", targetDir, os.PathSeparator)
// Remove queue directory and re-fill it // Create queue directory if it doesn't exist yet
os.RemoveAll(targetDir) _, folderErr := os.Stat(targetDir)
if os.IsNotExist(folderErr) {
os.Mkdir(targetDir, 0755) os.Mkdir(targetDir, 0755)
}
// Iterate over all files in the archive // Iterate over all files in the archive
for { for {