• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2020 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17"""Helper script for parsing custom fuzzing options."""
18import configparser
19import sys
20
21
22def parse_options(options_file_path, options_section):
23  """Parses the given file and returns options from the given section."""
24  parser = configparser.ConfigParser()
25  parser.read(options_file_path)
26
27  if not parser.has_section(options_section):
28    return None
29
30  options = parser[options_section]
31
32  if options_section == 'libfuzzer':
33    options_string = ' '.join(
34        '-%s=%s' % (key, value) for key, value in options.items())
35  else:
36    # Sanitizer options.
37    options_string = ':'.join(
38        '%s=%s' % (key, value) for key, value in options.items())
39
40  return options_string
41
42
43def main():
44  """Processes the arguments and prints the options in the correct format."""
45  if len(sys.argv) < 3:
46    sys.stderr.write('Usage: %s <path_to_options_file> <options_section>\n' %
47                     sys.argv[0])
48    return 1
49
50  options = parse_options(sys.argv[1], sys.argv[2])
51  if options is not None:
52    print(options)
53
54  return 0
55
56
57if __name__ == "__main__":
58  sys.exit(main())
59