Esempio n. 1
0
 def test_from_args(self):
     host = MockHost()
     parser = Args.make_parser('description', name_required=False)
     # netaddr should get called with 'just-four-random-words', and fail
     with self.assertRaises(RuntimeError):
         args = parser.parse_args(['--device', 'just-four-random-words'])
         device = Device.from_args(host, args)
Esempio n. 2
0
def main():
  parser = Args.make_parser(
      'Starts the named fuzzer.  Additional arguments are passed through.')
  args, fuzzer_args = parser.parse_known_args()

  host = Host()
  device = Device.from_args(host, args)
  fuzzer = Fuzzer.from_args(device, args)

  with Cipd.from_args(fuzzer, args) as cipd:
    if cipd.install():
      device.store(os.path.join(cipd.root, '*'), fuzzer.data_path('corpus'))

  print('\n****************************************************************')
  print(' Starting ' + str(fuzzer) + '.')
  print(' Outputs will be written to:')
  print('   ' + fuzzer.results())
  if not args.foreground:
    print(' You should be notified when the fuzzer stops.')
    print(' To check its progress, use `fx fuzz check ' + str(fuzzer) + '`.')
    print(' To stop it manually, use `fx fuzz stop ' + str(fuzzer) + '`.')
  print('****************************************************************\n')
  fuzzer.start(fuzzer_args)

  title = str(fuzzer) + ' has stopped.'
  body = 'Output written to ' + fuzzer.results() + '.'
  print(title)
  print(body)
  host.notify_user(title, body)
  return 0
Esempio n. 3
0
def main():
    parser = ArgParser('Lists corpus instances in CIPD for the named fuzzer')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        print(cipd.instances())
    return 0
Esempio n. 4
0
def main():
    parser = Args.make_parser(
        'Lists the fuzzing corpus instances in CIPD for a named fuzzer')
    args = parser.parse_args()

    host = Host()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)
    cipd = Cipd(fuzzer)

    if not cipd.list():
        return 1
    return 0
Esempio n. 5
0
def main():
    parser = Args.make_parser('Stops the named fuzzer.')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.is_running():
        print('Stopping ' + str(fuzzer) + '.')
        fuzzer.stop()
    else:
        print(str(fuzzer) + ' is already stopped.')
    return 0
Esempio n. 6
0
def main():
    parser = Args.make_parser(
        'Runs the named fuzzer on provided test units, or all current test ' +
        'units for the fuzzer. Use \'check-fuzzer\' to see current tests units.'
    )
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.repro(fuzzer_args) == 0:
        print('No matching artifacts found.')
        return 1
    return 0
Esempio n. 7
0
def main():
  parser = Args.make_parser(
      'Transfers corpus for a named fuzzer to a device', label_present=True)
  args = parser.parse_args()

  host = Host()
  device = Device.from_args(host, args)
  fuzzer = Fuzzer.from_args(device, args)

  if os.path.isdir(args.label):
    device.store(os.path.join(args.label, '*'), fuzzer.data_path('corpus'))
    return 0
  with Cipd.from_args(fuzzer, args, label=args.label) as cipd:
    if not cipd.install():
      return 1
    device.store(os.path.join(cipd.root, '*'), fuzzer.data_path('corpus'))
  return 0
Esempio n. 8
0
def main():
    parser = Args.make_parser(
        'Transfers a fuzzing corpus for a named fuzzer from a device to CIPD')
    args = parser.parse_args()

    host = Host()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.measure_corpus()[0] == 0:
        print('Ignoring ' + str(fuzzer) + '; corpus is empty.')
        return 0
    with Cipd.from_args(fuzzer, args) as cipd:
        device.fetch(fuzzer.data_path('corpus/*'), cipd.root)
        if not cipd.create():
            return 1
    return 0
Esempio n. 9
0
def main():
    parser = ArgParser(
        'Transfers a fuzzing corpus for a named fuzzer from a device to CIPD')
    args = parser.parse_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if fuzzer.measure_corpus()[0] == 0:
        print('Ignoring ' + str(fuzzer) + '; corpus is empty.')
        return 0
    with Corpus.from_args(fuzzer, args) as corpus:
        corpus.pull()
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.create()
    return 0
Esempio n. 10
0
def main():
    parser = ArgParser(
        'Starts the named fuzzer.  Additional arguments are passed through.')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    if not args.monitor:
        with Corpus.from_args(fuzzer, args) as corpus:
            cipd = Cipd(corpus)
            if not args.no_cipd:
                cipd.install('latest')
            corpus.push()

        print(
            '\n****************************************************************'
        )
        print(' Starting ' + str(fuzzer) + '.')
        print(' Outputs will be written to:')
        print('   ' + fuzzer.results())
        if not args.foreground:
            print(' You should be notified when the fuzzer stops.')
            print(' To check its progress, use `fx fuzz check ' + str(fuzzer) +
                  '`.')
            print(' To stop it manually, use `fx fuzz stop ' + str(fuzzer) +
                  '`.')
        print(
            '****************************************************************\n'
        )
        fuzzer.start(fuzzer_args)
        if not args.foreground:
            subprocess.Popen(['python', sys.argv[0], '--monitor', str(fuzzer)])
    else:
        fuzzer.monitor()
        title = str(fuzzer) + ' has stopped.'
        body = 'Output written to ' + fuzzer.results() + '.'
        print(title)
        print(body)
        host.notify_user(title, body)
    return 0
Esempio n. 11
0
def main():
  parser = Args.make_parser(
      'Minimizes the current corpus for the named fuzzer. This should be ' +
      'used after running the fuzzer for a while, or after incorporating a ' +
      'third-party corpus using \'fetch-corpus\'')
  args, fuzzer_args = parser.parse_known_args()

  host = Host.from_build()
  device = Device.from_args(host, args)
  fuzzer = Fuzzer.from_args(device, args)

  with Cipd.from_args(fuzzer, args) as cipd:
    if cipd.install():
      device.store(os.path.join(cipd.root, '*'), fuzzer.data_path('corpus'))
    if fuzzer.merge(fuzzer_args) == (0, 0):
      print('Corpus for ' + str(fuzzer) + ' is empty.')
      return 1
    device.fetch(fuzzer.data_path('corpus/*'), cipd.root)
    if not cipd.create():
      return 1
  return 0
Esempio n. 12
0
def main():
    parser = Args.make_parser(
        description='Reports status for the fuzzer matching NAME if provided, '
        +
        'or for all running fuzzers.  Status includes execution state, corpus '
        + 'size, and number of artifacts.',
        name_required=False)
    args = parser.parse_args()

    host = Host()
    device = Device.from_args(host, args)
    fuzzers = Fuzzer.filter(host.fuzzers, args.name)

    pids = device.getpids()
    silent = True
    for pkg, tgt in fuzzers:
        fuzzer = Fuzzer(device, pkg, tgt)
        if not args.name and tgt not in pids:
            continue
        silent = False
        if tgt in pids:
            print(str(fuzzer) + ': RUNNING')
        else:
            print(str(fuzzer) + ': STOPPED')
        print('    Output path:  ' + fuzzer.data_path())
        print('    Corpus size:  %d inputs / %d bytes' %
              fuzzer.measure_corpus())
        artifacts = fuzzer.list_artifacts()
        if len(artifacts) == 0:
            print('    Artifacts:    None')
        else:
            print('    Artifacts:    ' + artifacts[0])
            for artifact in artifacts[1:]:
                print('                  ' + artifact)
    if silent:
        print(
            'No fuzzers are running.  Include \'name\' to check specific fuzzers.'
        )
        return 1
    return 0
Esempio n. 13
0
def main():
    parser = ArgParser(
        'Minimizes the current corpus for the named fuzzer. This should be ' +
        'used after running the fuzzer for a while, or after incorporating a '
        + 'third-party corpus using \'fetch-corpus\'')
    args, fuzzer_args = parser.parse_known_args()

    host = Host.from_build()
    device = Device.from_args(host, args)
    fuzzer = Fuzzer.from_args(device, args)

    with Corpus.from_args(fuzzer, args) as corpus:
        cipd = Cipd(corpus)
        if not args.no_cipd:
            cipd.install('latest')
        corpus.push()
        if fuzzer.merge(fuzzer_args) == (0, 0):
            print('Corpus for ' + str(fuzzer) + ' is empty.')
            return 1
        corpus.pull()
        if not args.no_cipd:
            cipd.create()
    return 0