Commit Graph

819 Commits

Author SHA1 Message Date
iphydf 50094b7385 test: Add a protocol dump test to generate initial fuzzer input. 2022-04-19 23:42:47 +00:00
iphydf debedb3c94 test: Add a Null_System used in toxsave_harness.
This does nothing but has a working simple RNG.
2022-04-14 19:04:25 +00:00
iphydf 19b9cf3812 test: Enable fuzzing for TCP.
If the `recvbuf` network function returns 0 all the time, that means
there is never any data available on the TCP socket. This change makes
it so there is a random amount of data available on the TCP socket.

This invalidates the bootstrap fuzzer corpus.
2022-04-14 13:19:56 +00:00
iphydf d78ee9b12e fix: Fix potential array out-of-bounds in DHT random node retrieval.
It can't happen in almost every reality, except when the RNG is fairly
broken and doesn't add 2 fake DHT friends on startup. Still, this code
should be defensive and never index outside `num_friends` elements.
2022-04-10 23:17:15 +00:00
iphydf 60b71adbfa test: Don't abort fuzz test when tox_new fails.
Right now, it can't fail, but later we want the fuzzer to randomly let
I/O functions fail, so we shouldn't assert tox_new succeeded.
2022-04-10 22:35:00 +00:00
iphydf 27c27b7c8c refactor: Avoid static_cast in Fuzz_System functions.
Declutters the fuzz system code a bit, hiding the cast behind a `!`
operator.
2022-04-10 19:13:01 +00:00
jfreegman 616bd63021 Downgrade C++ version to 17 2022-04-10 12:44:04 -04:00
iphydf cb34fe12d1 test: Add more functionality to the bootstrap harness.
Ideally this would be able to reach some of the events, so we can write
code to respond to those events, but so far only the friend request
event actually happens.
2022-04-07 20:17:56 +00:00
iphydf 941026266e refactor: Allow overriding mono_time in tox_new.
This makes it so if mono_time is overridden, no monotonic time-related
system call is invoked in tox_new.
2022-04-03 22:48:16 +00:00
iphydf 378febffff cleanup: Use static_assert instead of assert where possible.
This avoids some "always true condition" warnings and lifts the errors
(if any) into compile time.
2022-04-03 17:58:14 +00:00
zugz (tox) e49a477a84 feat: add forwarding and announce request handling
This is the "server-side" part of the new friend finding system,
allowing DHT nodes to store small amounts of data and permit searching
for it. A forwarding (proxying) mechanism allows this to be used by TCP
clients, and deals with non-transitivity in the network.
2022-04-03 00:00:08 +00:00
iphydf dec1399776 test: Add fuzzer support functions for internal toxcore objects.
These help creating fuzzer fixtures with non-trivially constructed
objects and takes care of cleaning them up afterwards so the fuzzer code
can focus on the system under test.
2022-04-03 11:21:06 +00:00
iphydf cc31ff07fa feat: Add support for custom random number generator.
This can be used by fuzzers to make RNG-driven code deterministic (i.e.
based on the fuzzer input).
2022-04-01 14:06:05 +00:00
iphydf e04484efae cleanup: Remove unused random_testing program.
Fuzzers do a better job of this.
2022-04-01 09:20:04 +00:00
jfreegman 015305a088 Merge moderation portion of new groupchats codebase 2022-03-30 20:09:50 -04:00
iphydf 7db0c80c93 test: Add DHT and tox_events fuzz tests to the cmake build. 2022-03-29 22:57:23 +00:00
iphydf f39aac09e6 feat: Allow custom network functions.
The idea here is to have a `Network` object that contains functions for
network operations and an optional userdata object that can manage those
network operations. This allows e.g. a fuzzer to replace the network
functions with no-ops or fuzzer inputs, reducing the need for `#ifdef`s.
2022-03-29 22:03:26 +00:00
iphydf e4558a287c perf: Make time move a lot faster in fuzzing runs. 2022-03-27 22:52:35 +00:00
iphydf 478ef39b39 test: Add some support functions to make writing fuzzers easier. 2022-03-27 18:43:41 +00:00
sudden6 bc006beb4e cleanup: split CMakeLists.txt and add some missing targets 2022-03-27 20:09:10 +02:00
sudden6 48fb45887f try to save the fuzzed save file again
This should test some additional code paths.
2022-03-26 14:09:04 +01:00
iphydf 1928704065 test: Add fuzzer tests to the bazel build. 2022-03-25 18:48:41 +00:00
iphydf 2dcb946e62 cleanup: Reduce scope of array-typed variables where possible.
Cimple cannot actually find these without also causing false positives,
but I found them with cimple before removing the code causing false
positives again.
2022-03-21 12:02:46 +00:00
iphydf c3a938e38c cleanup: Avoid memset on structs.
Most of these were safe (some were not), but even the safe ones can
become unsafe (non-portable) later on when adding pointer or float members.
2022-03-19 12:32:36 +00:00
iphydf cff9a18e39 cleanup: Split util.c out of the network library.
Also, don't include ccompat.h in header files. Instead, explicitly
include it in .c files.
2022-03-04 10:33:11 +00:00
iphydf 163e9c3b03 cleanup: Remove more boolean conversions (and a bugfix).
These were found by the new stronger type check in cimple. The one
bugfix is in `crypto_sha512_cmp`, which used to think `crypto_verify_32`
returns bool while actually it's -1/0/1.
2022-02-26 00:03:56 +00:00
iphydf 093927ba4f test: Add mallocfail and proxy test to our coverage runs. 2022-02-25 01:55:28 +00:00
sudden6 e42441e3cf chore: remove DHT_test.c since it's unused 2022-02-22 22:30:27 +01:00
iphydf 6be655c56c cleanup: Return boolean constants, not ints from bool functions. 2022-02-22 17:50:17 +00:00
iphydf b7f95bbe70 cleanup: Remove any disallowed casts.
The ones in toxav weren't needed. The ones in network.c are
non-trivially correct. Now, the code is more easily verifiable.
2022-02-22 02:19:29 +00:00
iphydf f98137d697 refactor: Move tox_new_log to auto_test_support.
This is only used in auto tests.
2022-02-21 17:39:10 +00:00
iphydf 86a528a37a chore: Add a .clang-format that mostly agrees with astyle. 2022-02-21 16:16:16 +00:00
iphydf 6a6bc029de cleanup: Remove unused execution trace library. 2022-02-19 11:44:13 +00:00
iphydf 84a03bc2ed cleanup: Enable tokstyle's -Wlarge-struct-params. 2022-02-18 10:49:46 +00:00
iphydf 7b2f6c34c6 cleanup: Apply stronger type checks and fix errors.
Found a bug, too: file recv and chunk events were intermittently
converting to `uint32_t`, losing precision.
2022-02-17 22:34:56 +00:00
Maxim Biro 25216f86e7 Don't attempt to install the same package twice 2022-02-13 22:54:10 -05:00
sudden6 acf85eee46 fix: remove bogus asserts in fuzzer harness 2022-02-14 00:38:42 +01:00
iphydf a3cd1102f7 perf: Reduce minimal encoding size of packed events.
We're using a union-like encoding now with an enum telling which union
member to set.
2022-02-12 17:44:44 +00:00
iphydf 10f86f6c00 cleanup: Add more nonnull and nullable annotations. 2022-02-09 20:03:34 +00:00
iphydf 2ed9b1927f doc: Add doxygen configuration and netlify publishing. 2022-02-05 15:59:45 +00:00
jfreegman 5619b5e056 Make more functions take const pointers to IP_Port
We additionally now make local copies of the IP_Port param instead
of modifying the passed argument
2022-02-03 11:17:29 -05:00
iphydf fcabbd2ed4 chore: Disable some cimple warnings for now.
So we can push the latest cimple to toktok-stack and then start fixing
the warnings.
2022-02-03 01:50:23 +00:00
iphydf 5fbcbb6c83 cleanup: Remove uses of strcpy and sprintf.
Use of `strcpy` in these particular cases was safe, but it's hard to
tell and also useless. `strcpy` would effectively need to do another
`strlen` which we already did.

Also removed sprintf, which was also safe in this case but it's easier to
be "obviously safe", especially for static analysers.
2022-01-17 18:25:40 +00:00
iphydf 044ae636a3 chore: Mark unsafe code as testonly.
We want to ensure that nobody links against testing code in production.
2022-01-16 09:10:53 +00:00
iphydf 685b78d31d chore: Add asan/tsan bazel builds.
These have all dependencies built with asan/tsan, so they can do deeper
sanity checks such as checking what opus is doing with our buffers.

The asan check currently fails for me locally, so these are not yet set
to be required for PRs to be merged.
2022-01-12 20:33:21 +00:00
jfreegman 360acd0f42 Replace all instances of atoi with strtol
atoi doesn't check if the conversion from string to int succeeded
which doesn't allow us to do proper error handling.

We also now make sure that the port argument is a valid port
in addition to being properly converted
2022-01-12 14:08:45 -05:00
iphydf 9b7279ab24 chore: Run tokstyle with 3 cores.
This seems to be the sweet spot for the current tokstyle implementation.
4 cores gives the same speedup, 5 also, 6 makes it slower, and 2 also
makes it slower.
2022-01-12 18:52:46 +00:00
iphydf c1b32bd7a1 chore: Enable compiler layering check.
This ensures that we're explicit about what we depend on and avoids
transitive dependencies.
2022-01-11 15:26:32 +00:00
sudden6 e04b890817 add scripts to run the fuzzing process
This adds scripts and Dockerfiles to run the fuzzing process standalone
or with OSS-Fuzz/ClusterFuzzLite integrations.
2022-01-10 21:05:51 +01:00
sudden6 7dd8dbd897 intercept network, crypto and time
This fuzzing harness must be as deterministic as possible for the fuzzer
to detect additional coverage reliably.
2022-01-10 21:05:49 +01:00