LCOV - code coverage report
Current view: top level - test/fuzzer - fuzzer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 15 27 55.6 %
Date: 2019-04-19 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright 2016 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include <stddef.h>
       6             : #include <stdint.h>
       7             : #include <stdio.h>
       8             : #include <stdlib.h>
       9             : 
      10             : extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv);
      11             : extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
      12             : 
      13          37 : int main(int argc, char* argv[]) {
      14          37 :   if (LLVMFuzzerInitialize(&argc, &argv)) {
      15           0 :     fprintf(stderr, "Failed to initialize fuzzer target\n");
      16           0 :     return 1;
      17             :   }
      18             : 
      19          37 :   if (argc < 2) {
      20           0 :     fprintf(stderr, "USAGE: %s <input>\n", argv[0]);
      21           0 :     return 1;
      22             :   }
      23             : 
      24          37 :   FILE* input = fopen(argv[1], "rb");
      25             : 
      26          37 :   if (!input) {
      27           0 :     fprintf(stderr, "Failed to open '%s'\n", argv[1]);
      28           0 :     return 1;
      29             :   }
      30             : 
      31          37 :   fseek(input, 0, SEEK_END);
      32          37 :   size_t size = ftell(input);
      33          37 :   fseek(input, 0, SEEK_SET);
      34             : 
      35          37 :   uint8_t* data = reinterpret_cast<uint8_t*>(malloc(size));
      36          37 :   if (!data) {
      37           0 :     fclose(input);
      38           0 :     fprintf(stderr, "Failed to allocate %zu bytes\n", size);
      39           0 :     return 1;
      40             :   }
      41             : 
      42             :   size_t bytes_read = fread(data, 1, size, input);
      43          37 :   fclose(input);
      44             : 
      45          37 :   if (bytes_read != static_cast<size_t>(size)) {
      46           0 :     free(data);
      47           0 :     fprintf(stderr, "Failed to read %s\n", argv[1]);
      48           0 :     return 1;
      49             :   }
      50             : 
      51          37 :   int result = LLVMFuzzerTestOneInput(data, size);
      52             : 
      53          37 :   free(data);
      54             : 
      55          37 :   return result;
      56             : }

Generated by: LCOV version 1.10