OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Mutational ClusterFuzz fuzzer. A pre-built corpus of ipcdump files has | 6 """Mutational ClusterFuzz fuzzer. A pre-built corpus of ipcdump files has |
7 to be uploaded to ClusterFuzz along with this script. As chrome is being | 7 to be uploaded to ClusterFuzz along with this script. As chrome is being |
8 developed, the corpus will become out-of-date and needs to be updated. | 8 developed, the corpus will become out-of-date and needs to be updated. |
9 | 9 |
10 This fuzzer will pick some ipcdumps from the corpus, concatenate them with | 10 This fuzzer will pick some ipcdumps from the corpus, concatenate them with |
(...skipping 23 matching lines...) Expand all Loading... |
34 self.ipc_fuzzer_binary = utils.get_fuzzer_application_name() | 34 self.ipc_fuzzer_binary = utils.get_fuzzer_application_name() |
35 self.ipc_replay_binary = utils.get_replay_application_name() | 35 self.ipc_replay_binary = utils.get_replay_application_name() |
36 self.ipc_message_util_binary_path = os.path.join( | 36 self.ipc_message_util_binary_path = os.path.join( |
37 chrome_application_directory, self.ipc_message_util_binary) | 37 chrome_application_directory, self.ipc_message_util_binary) |
38 self.ipc_fuzzer_binary_path = os.path.join( | 38 self.ipc_fuzzer_binary_path = os.path.join( |
39 chrome_application_directory, self.ipc_fuzzer_binary) | 39 chrome_application_directory, self.ipc_fuzzer_binary) |
40 self.ipc_replay_binary_path = os.path.join( | 40 self.ipc_replay_binary_path = os.path.join( |
41 chrome_application_directory, self.ipc_replay_binary) | 41 chrome_application_directory, self.ipc_replay_binary) |
42 | 42 |
43 def set_corpus(self): | 43 def set_corpus(self): |
44 input_directory = self.args.input_dir | 44 # Corpus should be set per job as a fuzzer-specific environment variable. |
45 entries = os.listdir(input_directory) | 45 corpus = os.getenv('IPC_CORPUS_DIR', 'default') |
| 46 corpus_directory = os.path.join(self.args.input_dir, corpus) |
| 47 if not os.path.exists(corpus_directory): |
| 48 sys.exit('Corpus directory "%s" not found.' % corpus_directory) |
| 49 |
| 50 entries = os.listdir(corpus_directory) |
46 entries = [i for i in entries if i.endswith(utils.IPCDUMP_EXTENSION)] | 51 entries = [i for i in entries if i.endswith(utils.IPCDUMP_EXTENSION)] |
47 self.corpus = [os.path.join(input_directory, entry) for entry in entries] | 52 self.corpus = [os.path.join(corpus_directory, entry) for entry in entries] |
48 | 53 |
49 def create_mutated_ipcdump_testcase(self): | 54 def create_mutated_ipcdump_testcase(self): |
50 ipcdumps = ','.join(random.sample(self.corpus, IPCDUMP_MERGE_LIMIT)) | 55 ipcdumps = ','.join(random.sample(self.corpus, IPCDUMP_MERGE_LIMIT)) |
51 tmp_ipcdump_testcase = utils.create_temp_file() | 56 tmp_ipcdump_testcase = utils.create_temp_file() |
52 mutated_ipcdump_testcase = ( | 57 mutated_ipcdump_testcase = ( |
53 utils.random_ipcdump_testcase_path(self.args.output_dir)) | 58 utils.random_ipcdump_testcase_path(self.args.output_dir)) |
54 | 59 |
55 # Concatenate ipcdumps -> tmp_ipcdump. | 60 # Concatenate ipcdumps -> tmp_ipcdump. |
56 cmd = [ | 61 cmd = [ |
57 self.ipc_message_util_binary_path, | 62 self.ipc_message_util_binary_path, |
(...skipping 22 matching lines...) Expand all Loading... |
80 self.set_application_paths() | 85 self.set_application_paths() |
81 self.set_corpus() | 86 self.set_corpus() |
82 for _ in xrange(self.args.no_of_files): | 87 for _ in xrange(self.args.no_of_files): |
83 self.create_mutated_ipcdump_testcase() | 88 self.create_mutated_ipcdump_testcase() |
84 | 89 |
85 return 0 | 90 return 0 |
86 | 91 |
87 if __name__ == "__main__": | 92 if __name__ == "__main__": |
88 fuzzer = MutationalFuzzer() | 93 fuzzer = MutationalFuzzer() |
89 sys.exit(fuzzer.main()) | 94 sys.exit(fuzzer.main()) |
OLD | NEW |