示例#1
0
def write_dummy_file(input_dir):
    """Afl will refuse to run if the corpus directory is empty or contains empty
  files. So write the bare minimum to get afl to run if there is no corpus
  yet."""
    # TODO(metzman): Ask lcamtuf to allow AFL to run with an empty input corpus.
    dummy_input_path = os.path.join(input_dir, AFL_DUMMY_INPUT)
    if environment.is_trusted_host():
        from bot.untrusted_runner import file_host
        file_host.write_data_to_worker(' ', dummy_input_path)
    else:
        utils.write_data_to_file(' ', dummy_input_path)
示例#2
0
  def test_write_data_to_worker(self):
    """Tests remote write_data_to_worker."""
    dest_path = os.path.join(self.tmp_dir, 'dst')
    self.assertTrue(
        file_host.write_data_to_worker('write_data_to_worker', dest_path))

    with open(dest_path) as f:
      self.assertEqual(f.read(), 'write_data_to_worker')
示例#3
0
    def test_write_data_to_worker(self):
        """Test file_host.write_data_to_worker."""
        contents = ('A' * config.FILE_TRANSFER_CHUNK_SIZE +
                    'B' * config.FILE_TRANSFER_CHUNK_SIZE +
                    'C' * config.FILE_TRANSFER_CHUNK_SIZE)

        result = untrusted_runner_pb2.CopyFileToResponse(result=True)
        self.mock.stub().CopyFileTo.return_value = result

        self.assertTrue(file_host.write_data_to_worker(contents, '/file'))
        call_args = self.mock.stub().CopyFileTo.call_args
        self.assertEqual(call_args[1], {'metadata': [('path-bin', '/file')]})

        chunks = [chunk.data for chunk in call_args[0][0]]
        self.assertEqual(len(chunks), 3)

        data = ''.join(chunks)
        self.assertEqual(data, contents)