Commit Graph

5135 Commits

Author SHA1 Message Date
iphydf
efea12ed6f
Revert "fix: Allow onion paths to be built from more random nodes."
This reverts commit 5073882e0f.
2022-04-11 11:56:43 +00:00
iphydf
365ecd57f2
refactor: Move crypto utilities from util to crypto_core.
This makes more sense as a module for them to live in. Now, util no
longer depends on crypto_core and can thus potentially be used in
crypto_core in the future (functions like min/max may be useful).
2022-04-10 23:27:15 +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
5073882e0f
fix: Allow onion paths to be built from more random nodes.
Right now it only gets built from the first 2 friends in the DHT friend
list: either friend 0 and then 1 or friend 1 and then 0. The randomness
in this code doesn't make sense unless the intention was to select from
all friends, which the code will now do.

Also: use uniform random distribution to select the friends rather than
modulus, which is only uniform for powers of 2.
2022-04-10 22:10:32 +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
zugz (tox)
417d28d439
fix: really fix overrun added in e49a477a 2022-04-10 00:00:00 +00:00
jfreegman
7e38ead415
Add missing return on error
Note: This code cannot presently be called
2022-04-08 19:23:12 -04:00
iphydf
078baf08bb
test: Improve error messages in toxav_basic_test. 2022-04-08 18:05:24 +00:00
zugz (tox)
697e8d0264
fix leak and overrun added in e49a477a 2022-04-07 00:00:00 +00: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
e3fd8922a4
chore: Upgrade to C++20 in CMake build.
We need at least C++14 for `std::make_unique`, and would like to use
C++20 for designated initialisers to construct Network/Random vtables.
2022-04-07 19:57:05 +00:00
jfreegman
f68b1412b4
Merge group announce portion of new groupchats implementation 2022-04-06 10:56:09 -04:00
iphydf
2fb25b9328
refactor: Protect array unpacking against invalid lengths.
Each array element is at least 1 byte, so if there are fewer bytes than
array elements, the array size is invalid.
2022-04-05 20:52:47 +00:00
iphydf
c4beda4dd1
refactor: Rename announce functions into their own namespace.
This avoids common names like `on_stored` and `store_data` in global
symbols. Turns out, toxic also has a `store_data`.
2022-04-05 20:30:53 +00:00
iphydf
d539e34f91
chore: Add initial ESP32 docker build.
It won't actually run until we reduce memory consumption by 2 orders of
magnitude, but that'll be the eventual goal.
2022-04-05 20:11:18 +00:00
iphydf
3576df9d79
chore: Add MISRA-2012 check using cppcheck's misra addon.
Disabled a whole bunch of rules from the MISRA-C set. Some of them
should be fixed, but most of the ones we violate have good reasons. This
PR documents those reasons.
2022-04-04 20:29:54 +00:00
iphydf
d0728560bc
fix: Format IP as string again in error log.
In case DEBUG logging is disabled, the formatting done in the
`LOGGER_DEBUG` statement above will not occur, leaving uninitialised
memory here.
2022-04-04 10:37:32 +00:00
iphydf
7a4cc107c0
fix: Fix a stack overflow triggered by small DHT packets.
This isn't in production yet. It's in the new announce store code. The
problem was that a negative plain_len was converted to unsigned, which
made it a very large number.
2022-04-04 09:35:19 +00:00
iphydf
2c06ef6ad4
cleanup: Replace a series of if statements with a switch. 2022-04-04 09:02:48 +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
Robin Linden
6baabee695
chore: Add a shared library on Windows appveyor job
This also changes the Appveyor build to only build once, with tests,
instead of once without tests and once with tests.
2022-04-03 23:04:19 +02:00
Robin Linden
657d185de5
chore: Support producing shared libraries on Windows
The FLAT_OUTPUT_STRUCTURE CMake option was added to allow the tests to
find the .dlls.

The global data symbols were converted to functions to allow
WINDOWS_EXPORT_ALL_SYMBOLS handle them.

See:
https://cmake.org/cmake/help/v3.23/prop_tgt/WINDOWS_EXPORT_ALL_SYMBOLS.html
2022-04-03 23:04:11 +02:00
iphydf
ddda605509
fix: Don't crash if RNG init failed.
`system_random()` can fail and return NULL, which should be handled by
toxencryptsave functions.

Also synced function comments between .h and .c file for toxencryptsave.
2022-04-03 20:46:44 +00:00
zugz (tox)
4430515052
cleanup: remove populate_path_nodes_tcp
It was a no-op.
2022-04-03 00:00:00 +00:00
iphydf
7a3ead591f
cleanup: Use a struct for the ip_ntoa buffer.
Every use of this function needs to allocate the same buffer. None of
the callers uses a differently sized buffer, so we might as well put it
in a struct and have the type checker prove the buffer size is correct.

Also rename `ip_ntoa` to `net_ip_ntoa` to avoid clashes with ESP-IDF
system libraries which define this function as well.
2022-04-03 18:57:04 +00:00
iphydf
e4d1958ffa
refactor: Allow NULL logger; make it no-op in NDEBUG. 2022-04-03 18:29:22 +00:00
iphydf
4d5887cc58
test: Improve stability of forwarding_test.
By trying to create a tox tcp relay on 100 ports starting at 36570.
2022-04-03 18:14:01 +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
zugz (tox)
97acb39c1f
cleanup: add timed_auth module for ping_ids 2022-04-03 00:00:08 +00:00
zugz (tox)
7cee48d9c4
cleanup: clarify and isolate use of custom IP_Port values to denote TCP connections 2022-04-03 11:41:42 +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
c71b1218f8
chore(deps): Use upstream cmp directly instead of our fork.
The upstream maintainer is active and has merged our changes.
2022-04-03 09:02:31 +00:00
iphydf
b66f4959e2
chore: Add dependabot config.
To keep the third_party/cmp submodule up-to-date.
2022-04-03 08:45:09 +00:00
iphydf
e3ace8ca24
cleanup: Make *_free functions nullable.
These should be no-ops when passed a null pointer.
2022-04-02 21:28:26 +00:00
iphydf
eb07575334
cleanup: Remove layers in the cmake build.
Nothing checks whether these layers are actually observed. The bazel
build does check this, so there's no need to have this documentation in
the cmake build. It'll just go out of date.
2022-04-01 17:17:15 +00:00
iphydf
1f4aaf01cb
chore: Fix path to fuzzer binaries in clusterfuzz build. 2022-04-01 16:58:17 +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
660e346fce
cleanup: Disallow stack frames of over 9000 bytes.
This only happens in tests, which are easy to fix. Inside toxcore we
should actually be more stringent, but for now this helps already.
2022-04-01 13:57:16 +00:00
iphydf
8b407802dd
refactor: Rename bin_pack/unpack functions the same as cmp funcs.
No real reason to have different names. Also "bin" is shorter than
"bytes" to write.
2022-04-01 11:15:16 +00:00
iphydf
d0ebc21a0e
cleanup: Add Network object parameter for addr_resolve.
This function doesn't use Network yet, but it will in the future, and
for now it's better to pass Network to all network I/O functions.
2022-04-01 10:42:43 +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
iphydf
b09a1ff02d
cleanup: Remove all uses of TOX_*_MAX_SIZE macros.
We should use the functions for these instead.
2022-04-01 09:10:37 +00:00
zugz (tox)
3cc72f5f57
fix: fix typo in git command in INSTALL.md 2022-03-31 00:00:00 +00:00
iphydf
c8e5fd37ae
cleanup: Add include for assert.h for the fuzzing build.
See https://github.com/TokTok/c-toxcore/runs/5776684729?check_suite_focus=true#step:4:945.
2022-03-31 19:11:09 +00:00
iphydf
cc0c4a5fe1
cleanup: Move definitions of tox_private.h functions to tox_private.c.
Also moved lock/unlock to tox_private so they can be used across these 2
tox/tox_private translation units.
2022-03-31 18:49:26 +00:00
iphydf
9b2e887826
cleanup: Expand CONST_FUNCTION and remove the macro.
Generating functions is ugly. Ideally astyle wouldn't ask us to write 4
lines of code where 1 would be more readable, but such is life (until we
move to clang-format).
2022-03-31 18:35:45 +00:00
iphydf
ee42a5ca05
chore: Add uint8_t version of bin_pack for numbers.
This was the only one missing. Also added a test for integer
conversions: lossy ones are rejected, lossless ones are ok.
2022-03-31 17:09:15 +00:00