contrib/fuzz/dirs.cc
author Matt Harbison <matt_harbison@yahoo.com>
Sat, 21 Nov 2020 00:10:36 -0500
changeset 46037 9624bf057c2a
parent 43859 8766728dbce6
permissions -rw-r--r--
phabricator: allow local revisions to be specified with `phabupdate` It's way easier and less error prone to specify a revset after importing a series than to manually type in a series of Differentials. Unlike most revision oriented commands, this requires the `--rev` option explicitly because the existing `DREVSPEC` doesn't need to have the leading 'D', and therefore the meaning is ambiguous. I wouldn't have a problem giving precedence to the local revnum, but `phabread` and `phabimport` also use DREVSPEC, and local revisions make no sense there. I would be fine with modifying that definition to require the leading 'D', but I'm not sure how many people are used to not specifying it. Differential Revision: https://phab.mercurial-scm.org/D9356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43150
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     1
#include <Python.h>
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     2
#include <assert.h>
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     3
#include <stdlib.h>
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     4
#include <unistd.h>
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     5
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     6
#include "pyutil.h"
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     7
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     8
#include <string>
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
     9
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    10
extern "C" {
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    11
43859
8766728dbce6 fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents: 43150
diff changeset
    12
static PYCODETYPE *code;
43150
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    13
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    14
extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    15
{
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    16
	contrib::initpy(*argv[0]);
43859
8766728dbce6 fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents: 43150
diff changeset
    17
	code = (PYCODETYPE *)Py_CompileString(R"py(
43150
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    18
try:
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    19
  files = mdata.split('\n')
43859
8766728dbce6 fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents: 43150
diff changeset
    20
  d = parsers.dirs(files)
43150
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    21
  list(d)
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    22
  'a' in d
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    23
  if files:
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    24
    files[0] in d
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    25
except Exception as e:
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    26
  pass
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    27
  # uncomment this print if you're editing this Python code
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    28
  # to debug failures.
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    29
  # print e
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    30
)py",
43859
8766728dbce6 fuzz: add support for fuzzing under either Python 2 or 3
Augie Fackler <augie@google.com>
parents: 43150
diff changeset
    31
	                                      "fuzzer", Py_file_input);
43150
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    32
	return 0;
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    33
}
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    34
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    35
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    36
{
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    37
	// Don't allow fuzzer inputs larger than 100k, since we'll just bog
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    38
	// down and not accomplish much.
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    39
	if (Size > 100000) {
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    40
		return 0;
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    41
	}
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    42
	PyObject *mtext =
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    43
	    PyBytes_FromStringAndSize((const char *)Data, (Py_ssize_t)Size);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    44
	PyObject *locals = PyDict_New();
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    45
	PyDict_SetItemString(locals, "mdata", mtext);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    46
	PyObject *res = PyEval_EvalCode(code, contrib::pyglobals(), locals);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    47
	if (!res) {
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    48
		PyErr_Print();
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    49
	}
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    50
	Py_XDECREF(res);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    51
	Py_DECREF(locals);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    52
	Py_DECREF(mtext);
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    53
	return 0; // Non-zero return values are reserved for future use.
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    54
}
7ff40418c6bf fuzz: new fuzzer for dirs.c
Augie Fackler <augie@google.com>
parents:
diff changeset
    55
}