Commit Graph

31 Commits

Author SHA1 Message Date
Patrick Steinhardt
e54343a402 fileops: rename to "futils.h" to match function signatures
Our file utils functions all have a "futils" prefix, e.g.
`git_futils_touch`. One would thus naturally guess that their
definitions and implementation would live in files "futils.h" and
"futils.c", respectively, but in fact they live in "fileops.h".

Rename the files to match expectations.
2019-07-20 19:11:20 +02:00
Patrick Steinhardt
3c966fb4fb fuzzers: clean up header includes
There's multiple headers included in our fuzzers that aren't required at
all. Furthermore, some of them are not available on Win32, causing
builds to fail. Remove them to fix this.
2019-07-05 11:58:33 +02:00
Patrick Steinhardt
9d43d45b21 fuzzers: use git_buf_printf instead of snprintf
The `snprintf` function does not exist on Win32, it only has
`_snprintf_s` available. Let's just avoid any cross-platform hassle and
use our own `git_buf` functionality instead.
2019-07-05 11:58:33 +02:00
Patrick Steinhardt
a6b2fffd46 fuzzers: use POSIX emulation layer to unlink files
Use `p_unlink` instead of `unlink` to remove the generated packfiles in
our packfile fuzzer. Like this, we do not have to worry about using
proper includes that are known on all platforms, especially Win32.
2019-07-05 11:58:33 +02:00
Patrick Steinhardt
6905581304 fuzzers: make printf formatters cross-platform compatible
The `printf` formatters in our standalone fuzzing driver are currently
using the "%m" specifier, which is a GNU extension that prints the error
message for the error code in `errno`. As we're using libgit2 functions
in both cases anyway, let's just use `git_error_last` instead to make
this valid on all platforms.
2019-07-05 11:58:33 +02:00
Patrick Steinhardt
48d563286c fuzzers: implement mkdtemp alternative for Win32
The `mkdtemp` function is not available on Windows, so our download_refs
fuzzer will fail to compile on Windows. Provide an alternative
implementation to fix it.
2019-07-05 11:58:32 +02:00
Edward Thomson
d3a440ca19 fuzzers: use system includes
Use the system includes (defined by libgit2) as the fuzzer includes.
The fuzzers link against internal libgit2 API and therefore need to have
the full include path that libgit2 uses.
2019-05-19 11:10:09 +01:00
Edward Thomson
a1ef995dc0 indexer: use git_indexer_progress throughout
Update internal usage of `git_transfer_progress` to
`git_indexer_progreses`.
2019-02-22 11:25:14 +00:00
Edward Thomson
1c3daccf1a fuzzers: don't use deprecated types 2019-01-25 09:06:50 +00:00
Edward Thomson
115a6c50c9 errors: remove giterr usage in fuzzers 2019-01-22 22:30:37 +00:00
Edward Thomson
83151018ef object_type: convert final internal users to new names
Update some missed types that were continuing to use the old `GIT_OBJ`
names.
2019-01-17 11:03:19 +00:00
Carlos Martín Nieto
7615794c12 Merge pull request #4845 from pks-t/pks/object-fuzzer
Object parsing fuzzer
2018-10-15 18:08:13 +02:00
Nelson Elhage
463c21e2c1 Apply code review feedback 2018-10-11 13:27:06 +00:00
Patrick Steinhardt
a1d5fd0630 fuzzers: add object parsing fuzzer
Add a simple fuzzer that exercises our object parser code. The fuzzer
is quite trivial in that it simply passes the input data directly to
`git_object__from_raw` for each of the four object types.
2018-10-11 12:46:11 +02:00
Patrick Steinhardt
6956a95477 fuzzers: initialize libgit2 in standalone driver
The standalone driver for libgit2's fuzzing targets makes use of
functions from libgit2 itself. While this is totally fine to do, we need
to make sure to always have libgit2 initialized via `git_libgit2_init`
before we call out to any of these. While this happens in most cases as
we call `LLVMFuzzerInitialize`, which is provided by our fuzzers and
which right now always calls `git_libgit2_init`, one exception to this
rule is our error path when not enough arguments have been given. In
this case, we will call `git_vector_free_deep` without libgit2 having
been initialized. As we did not set up our allocation functions in that
case, this will lead to a segmentation fault.

Fix the issue by always initializing and shutting down libgit2 in the
standalone driver. Note that we cannot let this replace the
initialization in `LLVMFuzzerInitialize`, as it is required when using
the "real" fuzzers by LLVM without our standalone driver. It's no
problem to call the initialization and deinitialization functions
multiple times, though.
2018-10-11 12:26:44 +02:00
Nelson Elhage
416aafd14c fuzzers: Port config_file_fuzzer to the new in-memory backend 2018-10-09 02:45:22 +00:00
Edward Thomson
6d6bec0cc6 fuzzer: update for indexer changes 2018-08-26 11:52:21 +01:00
Nelson Elhage
f556dea6e2 Add a proper write loop 2018-08-16 15:10:51 +00:00
Nelson Elhage
b8d4578abb Add a copyright header. 2018-08-14 04:01:30 +00:00
Nelson Elhage
298f5df6ff Further review comments, fix the build 2018-08-14 04:01:04 +00:00
Nelson Elhage
8189642d24 Reformat 2018-08-14 03:55:58 +00:00
Nelson Elhage
bcfa762b36 Add a config file to the corpus 2018-08-05 03:14:56 +00:00
Nelson Elhage
1a8e22e846 Add a config file fuzzer 2018-08-05 03:13:49 +00:00
Patrick Steinhardt
e38ddc90bf fuzzers: limit maximum pack object count
By default, libgit2 allows up to 2^32 objects when downloading a
packfile from a remote. For each of these objects, libgit2 will allocate
up to two small structs, which in total adds up to quite a lot of
memory. As a result, our fuzzers might run out of memory rather quick in
case where they receive as input a packfile with such a huge count of
objects.

Limit the packfile object count to 10M objects. This is sufficiently big
to still work with most largish repos (linux.git has around 6M objects
as of now), but small enough to not cause the fuzzer to OOM.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
5db64e2f1b fuzzers: convert download_refs fuzzer to C
Convert the "download_refs" fuzzer from C++ to C. Rename the source file
to have it be picked up by our build system.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
730c0edb50 fuzzers: import download_refs fuzzer from oss-fuzz
This is a direct copy of the code from google/oss-fuzz, written by
Nelson Elhage (@nelhage). Note that due to the ".cc" ending, the file
will not yet be picked up by the build system. This is intended, as
currently that file is partly written in C++, requiring a conversion to
C.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
de53972f65 fuzzers: avoid use of libgit2 internals in packfile_raw
The packfile_raw fuzzer is using some internal APIs from libgit2, which
makes it hard to compile it as part of the oss-fuzz project. As oss-fuzz
requires us to link against the C++ FuzzingEngine library, we cannot use
"-DBUILD_FUZZERS=ON" directly but instead have to first compile an
object from our fuzzers and then link against the C++ library. Compiling
the fuzzer objects thus requires an external invocation of CC, and we
certainly don't want to do further black magic by adding libgit2's
private source directory to the header include path.

To fix the issue, convert the code to not use any internal APIs. Besides
some headers which we have to add now, this also requires us to change
to the hashing function of the ODB. Note that this will change the
hashing result, as we have previously not prepended the object header to
the data that is to be hashed. But this shouldn't matter in practice, as
we don't care for the hash value anyway.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
bf3382d544 cmake: remove need to add "-fsanitize=fuzzer" flag for fuzzers
Right now, users are being instrucded to add the
"-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=fuzzer" flag when they want to
build our fuzzers. This is error-prone and user unfriendly. Instead,
just add the flag to our fuzzers' build instructions so that it happens
automatically. Adjust the README accordingly.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
07cf8b38db cmake: use C90 standard for our fuzzing targets
Like all our other internal code, we want to force the use of C90 for
our fuzzers. Do so by setting the "C_STANDARD" property of our fuzzing
targets.
2018-08-03 09:50:35 +02:00
Patrick Steinhardt
ad087303df fuzzers: move readme to docs/fuzzing.md 2018-08-03 09:50:35 +02:00
Patrick Steinhardt
59328ed84e fuzzers: rename "fuzz" directory to match our style
Our layout uses names like "examples" or "tests" which is why the "fuzz"
directory doesn't really fit in here. Rename the directory to be called
"fuzzers" instead. Furthermore, we rename the fuzzer "fuzz_packfile_raw"
to "packfile_raw_fuzzer", which is also in line with the already
existing fuzzer at google/oss-fuzz.

While at it, rename the "packfile_raw" fuzzer to instead just be called
"packfile" fuzzer.
2018-08-03 09:50:35 +02:00