Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef TOOLS_IPC_FUZZER_MUTATE_FUZZER_H_ | |
| 6 #define TOOLS_IPC_FUZZER_MUTATE_FUZZER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "ipc/ipc_message.h" | |
| 14 #include "tools/ipc_fuzzer/message_lib/message_file.h" | |
|
Tom Sepez
2015/03/18 18:49:19
Nit: does message_file.h need to be in this header
| |
| 15 | |
| 16 namespace ipc_fuzzer { | |
| 17 | |
| 18 // Interface implemented by those who generate basic types. The types all | |
| 19 // correspond to the types which a pickle from base/pickle.h can pickle, | |
| 20 // plus the floating point types. | |
| 21 class Fuzzer { | |
| 22 public: | |
| 23 // Functions for various data types. | |
| 24 virtual void FuzzBool(bool* value) = 0; | |
| 25 virtual void FuzzInt(int* value) = 0; | |
| 26 virtual void FuzzLong(long* value) = 0; | |
| 27 virtual void FuzzSize(size_t* value) = 0; | |
| 28 virtual void FuzzUChar(unsigned char* value) = 0; | |
| 29 virtual void FuzzWChar(wchar_t* value) = 0; | |
| 30 virtual void FuzzUInt16(uint16* value) = 0; | |
| 31 virtual void FuzzUInt32(uint32* value) = 0; | |
| 32 virtual void FuzzInt64(int64* value) = 0; | |
| 33 virtual void FuzzUInt64(uint64* value) = 0; | |
| 34 virtual void FuzzFloat(float* value) = 0; | |
| 35 virtual void FuzzDouble(double *value) = 0; | |
| 36 virtual void FuzzString(std::string* value) = 0; | |
| 37 virtual void FuzzString16(base::string16* value) = 0; | |
| 38 virtual void FuzzData(char* data, int length) = 0; | |
| 39 virtual void FuzzBytes(void* data, int data_len) = 0; | |
| 40 | |
| 41 // Used to determine if a completely new value should be generated for | |
| 42 // certain types instead of attempting to modify the existing one. | |
| 43 virtual bool ShouldGenerate(); | |
| 44 }; | |
| 45 | |
| 46 class NoOpFuzzer : public Fuzzer { | |
| 47 public: | |
| 48 NoOpFuzzer() {} | |
| 49 virtual ~NoOpFuzzer() {} | |
| 50 | |
| 51 void FuzzBool(bool* value) override {} | |
| 52 void FuzzInt(int* value) override {} | |
| 53 void FuzzLong(long* value) override {} | |
| 54 void FuzzSize(size_t* value) override {} | |
| 55 void FuzzUChar(unsigned char* value) override {} | |
| 56 void FuzzWChar(wchar_t* value) override {} | |
| 57 void FuzzUInt16(uint16* value) override {} | |
| 58 void FuzzUInt32(uint32* value) override {} | |
| 59 void FuzzInt64(int64* value) override {} | |
| 60 void FuzzUInt64(uint64* value) override {} | |
| 61 void FuzzFloat(float* value) override {} | |
| 62 void FuzzDouble(double* value) override {} | |
| 63 void FuzzString(std::string* value) override {} | |
| 64 void FuzzString16(base::string16* value) override {} | |
| 65 void FuzzData(char* data, int length) override {} | |
| 66 void FuzzBytes(void* data, int data_len) override {} | |
| 67 }; | |
| 68 | |
| 69 typedef IPC::Message* (*FuzzerFunction)(IPC::Message*, Fuzzer*); | |
| 70 | |
| 71 // Used for mutating messages. Once populated, the map associates a message ID | |
| 72 // with a FuzzerFunction used for mutation of that message type. | |
| 73 typedef base::hash_map<uint32, FuzzerFunction> FuzzerFunctionMap; | |
| 74 void PopulateFuzzerFunctionMap(FuzzerFunctionMap* map); | |
| 75 | |
| 76 // Used for generating new messages. Once populated, the vector contains | |
| 77 // FuzzerFunctions for all message types that we know how to generate. | |
| 78 typedef std::vector<FuzzerFunction> FuzzerFunctionVector; | |
| 79 void PopulateFuzzerFunctionVector(FuzzerFunctionVector* function_vector); | |
| 80 | |
| 81 // Since IPC::Message can be serialized, we also track a global function vector | |
| 82 // to handle generation of new messages while fuzzing. | |
| 83 extern FuzzerFunctionVector g_function_vector; | |
| 84 | |
| 85 } // namespace ipc_fuzzer | |
| 86 | |
| 87 #endif // TOOLS_IPC_FUZZER_MUTATE_FUZZER_H_ | |
| OLD | NEW |