Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3980)

Unified Diff: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h

Issue 1139673004: Harden writer of munged bitcode for fuzzing (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix issues in last patch. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
index d9a46ab91a2c0a36225fa89fa97b9bd74a8fc0ec..3181331a51398d9782a2dfb5f82110ec18cfb8b3 100644
--- a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
+++ b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
@@ -73,13 +73,13 @@ public:
}
/// Creates MungedInput and DumpStream for running tests, based on
- /// given Munges.
- void setupTest(
+ /// given Munges. Returns true if able to set up test.
+ bool setupTest(
const char *TestName, const uint64_t Munges[], size_t MungesSize,
bool AddHeader);
- /// Cleans up state after a test.
- void cleanupTest();
+ /// Cleans up state after a test. Returns true if no errors found.
+ bool cleanupTest();
/// Returns the resulting string generated by the corresponding test.
const std::string &getTestResults() const {
@@ -110,6 +110,16 @@ public:
WriteFlags.setWriteBadAbbrevIndex(NewValue);
}
+ /// Get access to munged bitcodes.
+ NaClMungedBitcode &getMungedBitcode() {
+ return MungedBitcode;
+ }
+
+ /// Apply given munges to the munged bitcode.
+ void munge(const uint64_t Munges[], size_t MungesSize) {
+ MungedBitcode.munge(Munges, MungesSize, RecordTerminator);
+ }
+
protected:
// The bitcode records being munged.
NaClMungedBitcode MungedBitcode;
@@ -151,6 +161,35 @@ protected:
}
};
+/// Class to run tests writing munged bitcode.
+class NaClWriteMunger : public NaClBitcodeMunger {
+public:
+ NaClWriteMunger(const uint64_t Records[], size_t RecordsSize,
+ uint64_t RecordTerminator)
+ : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
+
+ /// Writes munged bitcode and puts error messages into DumpResults.
+ /// Returns true if successful.
+ bool runTest(const char* TestName, const uint64_t Munges[],
+ size_t MungesSize);
+
+ /// Same as above, but without test name.
+ bool runTest(const uint64_t Munges[], size_t MungesSize) {
+ return runTest("Test", Munges, MungesSize);
+ }
+
+ /// Same as above, but without any edits.
+ bool runTest(const char* TestName) {
+ uint64_t NoMunges[] = {0};
+ return runTest(TestName, NoMunges, 0);
+ }
+
+ /// Same as above, but without test name.
+ bool runTest() {
+ return runTest("Test");
+ }
+};
+
/// Class to run tests for function llvm::NaClObjDump.
class NaClObjDumpMunger : public NaClBitcodeMunger {
public:
@@ -182,12 +221,17 @@ public:
return runTestWithFlags(TestName, true, false, false);
}
- /// Same as runTest, but only print out assembly and errors.
+ /// Same as above but without test name.
+ bool runTest() {
+ return runTest("Test");
+ }
+
+ /// Same as above, but only print out assembly and errors.
bool runTestForAssembly(const char *TestName) {
return runTestWithFlags(TestName, true, true, false);
}
- /// Same as runTest, but only generate error messages.
+ /// Same as above, but only generate error messages.
bool runTestForErrors(const char *TestName) {
return runTestWithFlags(TestName, true, true, true);
}
@@ -212,6 +256,10 @@ public:
return runTestWithFlags(TestName, Munges, MungesSize, true, false, false);
}
+ bool runTest(const uint64_t Munges[], size_t MungesSize) {
+ return runTest("Test", Munges, MungesSize);
+ }
+
bool runTestForAssembly(const char* TestName, const uint64_t Munges[],
size_t MungesSize) {
return runTestWithFlags(TestName, Munges, MungesSize, true, true, false);
@@ -235,6 +283,11 @@ public:
bool runTest(const char* TestName, const uint64_t Munges[],
size_t MungesSize, bool VerboseErrors);
+ /// Same as above, but without test name.
+ bool runTest(const uint64_t Munges[], size_t MungesSize, bool VerboseErrors) {
+ return runTest("Test", Munges, MungesSize, VerboseErrors);
+ }
+
// Same as above, but without any edits.
bool runTest(const char* TestName, bool VerboseErrors) {
uint64_t NoMunges[] = {0};
« no previous file with comments | « no previous file | include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698