contrib/fuzz/fm1readmarkers.cc
changeset 43859 8766728dbce6
parent 41024 6a951f535fee
equal deleted inserted replaced
43858:b0867b7751ba 43859:8766728dbce6
     7 
     7 
     8 #include "pyutil.h"
     8 #include "pyutil.h"
     9 
     9 
    10 extern "C" {
    10 extern "C" {
    11 
    11 
    12 static PyCodeObject *code;
    12 static PYCODETYPE *code;
    13 
    13 
    14 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
    14 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
    15 {
    15 {
    16 	contrib::initpy(*argv[0]);
    16 	contrib::initpy(*argv[0]);
    17 	code = (PyCodeObject *)Py_CompileString(R"py(
    17 	code = (PYCODETYPE *)Py_CompileString(R"py(
    18 from parsers import fm1readmarkers
       
    19 def maybeint(s, default):
    18 def maybeint(s, default):
    20     try:
    19     try:
    21         return int(s)
    20         return int(s)
    22     except ValueError:
    21     except ValueError:
    23         return default
    22         return default
    29         stop, data = parts
    28         stop, data = parts
    30         offset = 0
    29         offset = 0
    31     else:
    30     else:
    32         offset = stop = 0
    31         offset = stop = 0
    33     offset, stop = maybeint(offset, 0), maybeint(stop, len(data))
    32     offset, stop = maybeint(offset, 0), maybeint(stop, len(data))
    34     fm1readmarkers(data, offset, stop)
    33     parsers.fm1readmarkers(data, offset, stop)
    35 except Exception as e:
    34 except Exception as e:
    36     pass
    35     pass
    37     # uncomment this print if you're editing this Python code
    36     # uncomment this print if you're editing this Python code
    38     # to debug failures.
    37     # to debug failures.
    39     # print e
    38     # print e
    40 )py",
    39 )py",
    41 	                                        "fuzzer", Py_file_input);
    40 	                                      "fuzzer", Py_file_input);
    42 	return 0;
    41 	return 0;
    43 }
    42 }
    44 
    43 
    45 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
    44 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
    46 {
    45 {