| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Fuzz testing for EncodedProgram serialized format and assembly. | 5 // Fuzz testing for EncodedProgram serialized format and assembly. |
| 6 // | 6 // |
| 7 // We would like some assurance that if an EncodedProgram is malformed we will | 7 // We would like some assurance that if an EncodedProgram is malformed we will |
| 8 // not crash. The EncodedProgram could be malformed either due to malicious | 8 // not crash. The EncodedProgram could be malformed either due to malicious |
| 9 // attack to due to an error in patch generation. | 9 // attack to due to an error in patch generation. |
| 10 // | 10 // |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 // Returns true if could assemble, false if rejected. | 30 // Returns true if could assemble, false if rejected. |
| 31 bool TryAssemble(const std::string& buffer, std::string* output) const; | 31 bool TryAssemble(const std::string& buffer, std::string* output) const; |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Loads an executable and does fuzz testing in the serialized format. | 34 // Loads an executable and does fuzz testing in the serialized format. |
| 35 void DecodeFuzzTest::FuzzExe(const char* file_name) const { | 35 void DecodeFuzzTest::FuzzExe(const char* file_name) const { |
| 36 std::string file1 = FileContents(file_name); | 36 std::string file1 = FileContents(file_name); |
| 37 | 37 |
| 38 const void* original_buffer = file1.c_str(); | 38 const void* original_buffer = file1.c_str(); |
| 39 size_t original_length = file1.size(); | 39 size_t original_length = file1.length(); |
| 40 | 40 |
| 41 courgette::AssemblyProgram* program = NULL; | 41 courgette::AssemblyProgram* program = NULL; |
| 42 const courgette::Status parse_status = | 42 const courgette::Status parse_status = |
| 43 courgette::ParseDetectedExecutable(original_buffer, original_length, | 43 courgette::ParseDetectedExecutable(original_buffer, original_length, |
| 44 &program); | 44 &program); |
| 45 EXPECT_EQ(courgette::C_OK, parse_status); | 45 EXPECT_EQ(courgette::C_OK, parse_status); |
| 46 | 46 |
| 47 courgette::EncodedProgram* encoded = NULL; | 47 courgette::EncodedProgram* encoded = NULL; |
| 48 | 48 |
| 49 const courgette::Status encode_status = Encode(program, &encoded); | 49 const courgette::Status encode_status = Encode(program, &encoded); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 DeleteEncodedProgram(encoded); | 195 DeleteEncodedProgram(encoded); |
| 196 | 196 |
| 197 return result; | 197 return result; |
| 198 } | 198 } |
| 199 | 199 |
| 200 TEST_F(DecodeFuzzTest, All) { | 200 TEST_F(DecodeFuzzTest, All) { |
| 201 FuzzExe("setup1.exe"); | 201 FuzzExe("setup1.exe"); |
| 202 FuzzExe("elf-32-1.exe"); |
| 202 } | 203 } |
| 203 | 204 |
| 204 int main(int argc, char** argv) { | 205 int main(int argc, char** argv) { |
| 205 return base::TestSuite(argc, argv).Run(); | 206 return base::TestSuite(argc, argv).Run(); |
| 206 } | 207 } |
| OLD | NEW |