mirror of https://github.com/google/oss-fuzz.git
Use same filename for the input file created in disk (#994)
* Use the same file name always to avoid creating new files * Minor: formatting changes * Use PID for the filename
This commit is contained in:
parent
e68fd86c32
commit
6b302b9e61
|
@ -1,20 +1,27 @@
|
|||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "rar.hpp"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
char filename[] = "mytemp.XXXXXX";
|
||||
int fd = mkstemp(filename);
|
||||
write(fd, data, size);
|
||||
std::stringstream ss;
|
||||
ss << "temp-" << getpid() << ".rar";
|
||||
static const std::string filename = ss.str();
|
||||
std::ofstream file(filename,
|
||||
std::ios::binary | std::ios::out | std::ios::trunc);
|
||||
if (!file.is_open()) {
|
||||
return 0;
|
||||
}
|
||||
file.write(reinterpret_cast<const char *>(data), size);
|
||||
file.close();
|
||||
|
||||
std::unique_ptr<CommandData> cmd_data(new CommandData);
|
||||
cmd_data->ParseArg(const_cast<wchar_t *>(L"-p"));
|
||||
cmd_data->ParseArg(const_cast<wchar_t *>(L"x"));
|
||||
cmd_data->ParseDone();
|
||||
std::wstring wide_filename(filename, filename + strlen(filename));
|
||||
std::wstring wide_filename(filename.begin(), filename.end());
|
||||
cmd_data->AddArcName(wide_filename.c_str());
|
||||
|
||||
try {
|
||||
|
@ -23,8 +30,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|||
} catch (...) {
|
||||
}
|
||||
|
||||
close(fd);
|
||||
unlink(filename);
|
||||
unlink(filename.c_str());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue