diff options
author | Kostya Serebryany <kcc@google.com> | 2015-08-12 00:55:09 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-08-12 00:55:09 +0000 |
commit | ac25eeba766295f35ccd3b055c44848c0c4305f9 (patch) | |
tree | 5b1ae329b14010ec278e218f2d99c639fe844879 /llvm/lib/Fuzzer/FuzzerIO.cpp | |
parent | 592b2cc2468ccc444d5e7c420010f7d6a98a3bd2 (diff) | |
download | llvm-ac25eeba766295f35ccd3b055c44848c0c4305f9.zip llvm-ac25eeba766295f35ccd3b055c44848c0c4305f9.tar.gz llvm-ac25eeba766295f35ccd3b055c44848c0c4305f9.tar.bz2 |
[libFuzzer] use raw C IO to reduce the risk of a deadlock in a signal handler.
llvm-svn: 244707
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerIO.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerIO.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerIO.cpp b/llvm/lib/Fuzzer/FuzzerIO.cpp index 1d25389..f0295e9 100644 --- a/llvm/lib/Fuzzer/FuzzerIO.cpp +++ b/llvm/lib/Fuzzer/FuzzerIO.cpp @@ -66,8 +66,11 @@ void CopyFileToErr(const std::string &Path) { } void WriteToFile(const Unit &U, const std::string &Path) { - std::ofstream OF(Path); - OF.write((const char*)U.data(), U.size()); + // Use raw C interface because this function may be called from a sig handler. + FILE *Out = fopen(Path.c_str(), "w"); + if (!Out) return; + fwrite(U.data(), sizeof(U[0]), U.size(), Out); + fclose(Out); } void ReadDirToVectorOfUnits(const char *Path, std::vector<Unit> *V, |