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 try: |
46 corpus = os.environ['CORPUS'] | |
inferno
2015/05/11 21:22:43
os.getenv('CORPUS', 'default') is better here. no
| |
47 except KeyError: | |
48 corpus = 'default' | |
49 corpus_directory = os.path.join(self.args.input_dir, corpus) | |
inferno
2015/05/11 21:22:43
new-line before this line.
| |
50 if not os.path.exists(corpus_directory): | |
51 sys.exit('Corpus directory "%s" not found.' % corpus_directory) | |
52 | |
53 entries = os.listdir(corpus_directory) | |
46 entries = [i for i in entries if i.endswith(utils.IPCDUMP_EXTENSION)] | 54 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] | 55 self.corpus = [os.path.join(input_directory, entry) for entry in entries] |
48 | 56 |
49 def create_mutated_ipcdump_testcase(self): | 57 def create_mutated_ipcdump_testcase(self): |
50 ipcdumps = ','.join(random.sample(self.corpus, IPCDUMP_MERGE_LIMIT)) | 58 ipcdumps = ','.join(random.sample(self.corpus, IPCDUMP_MERGE_LIMIT)) |
51 tmp_ipcdump_testcase = utils.create_temp_file() | 59 tmp_ipcdump_testcase = utils.create_temp_file() |
52 mutated_ipcdump_testcase = ( | 60 mutated_ipcdump_testcase = ( |
53 utils.random_ipcdump_testcase_path(self.args.output_dir)) | 61 utils.random_ipcdump_testcase_path(self.args.output_dir)) |
54 | 62 |
55 # Concatenate ipcdumps -> tmp_ipcdump. | 63 # Concatenate ipcdumps -> tmp_ipcdump. |
(...skipping 24 matching lines...) Expand all Loading... | |
80 self.set_application_paths() | 88 self.set_application_paths() |
81 self.set_corpus() | 89 self.set_corpus() |
82 for _ in xrange(self.args.no_of_files): | 90 for _ in xrange(self.args.no_of_files): |
83 self.create_mutated_ipcdump_testcase() | 91 self.create_mutated_ipcdump_testcase() |
84 | 92 |
85 return 0 | 93 return 0 |
86 | 94 |
87 if __name__ == "__main__": | 95 if __name__ == "__main__": |
88 fuzzer = MutationalFuzzer() | 96 fuzzer = MutationalFuzzer() |
89 sys.exit(fuzzer.main()) | 97 sys.exit(fuzzer.main()) |
OLD | NEW |