Skip to content

Commit 2ccecdc

Browse files
committed
chore: Add remaining fuzz tests to cflite.
So we can run them daily and get coverage info from them.
1 parent 4626c2e commit 2ccecdc

File tree

10 files changed

+117
-59
lines changed

10 files changed

+117
-59
lines changed

.cirrus.yml

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
1-
# TODO(iphydf): Reactivate when we have quota again in February 2025.
2-
# ---
3-
# freebsd_task:
4-
# timeout_in: 5m
5-
# freebsd_instance:
6-
# image_family: freebsd-14-1
7-
# configure_script:
8-
# - PAGER=cat ASSUME_ALWAYS_YES=YES pkg install
9-
# cmake
10-
# git
11-
# gmake
12-
# googletest
13-
# libconfig
14-
# libsodium
15-
# libvpx
16-
# ninja
17-
# opus
18-
# pkgconf
19-
# - git submodule update --init --recursive
20-
# test_all_script:
21-
# - |
22-
# # TODO(iphydf): Investigate FreeBSD failures on these tests.
23-
# sed -Ei -e '/\(dht_nodes_request_api\)/s/^/#/' auto_tests/CMakeLists.txt
24-
# cmake . \
25-
# -DMIN_LOGGER_LEVEL=TRACE \
26-
# -DMUST_BUILD_TOXAV=ON \
27-
# -DNON_HERMETIC_TESTS=OFF \
28-
# -DTEST_TIMEOUT_SECONDS=50 \
29-
# -DUSE_IPV6=OFF \
30-
# -DAUTOTEST=ON \
31-
# -GNinja
32-
# cmake --build . --target install
33-
# ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3 || ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3
1+
---
2+
freebsd_task:
3+
timeout_in: 5m
4+
freebsd_instance:
5+
image_family: freebsd-14-1
6+
configure_script:
7+
- PAGER=cat ASSUME_ALWAYS_YES=YES pkg install
8+
cmake
9+
git
10+
gmake
11+
googletest
12+
libconfig
13+
libsodium
14+
libvpx
15+
ninja
16+
opus
17+
pkgconf
18+
- git submodule update --init --recursive
19+
test_all_script:
20+
- |
21+
# TODO(iphydf): Investigate FreeBSD failures on these tests.
22+
sed -Ei -e '/\(dht_nodes_request_api\)/s/^/#/' auto_tests/CMakeLists.txt
23+
cmake . \
24+
-DMIN_LOGGER_LEVEL=TRACE \
25+
-DMUST_BUILD_TOXAV=ON \
26+
-DNON_HERMETIC_TESTS=OFF \
27+
-DTEST_TIMEOUT_SECONDS=50 \
28+
-DUSE_IPV6=OFF \
29+
-DAUTOTEST=ON \
30+
-GNinja
31+
cmake --build . --target install
32+
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3 || ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:3

.clusterfuzzlite/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,23 @@
33
# We want to use the latest tools always
44
FROM gcr.io/oss-fuzz-base/base-builder:latest
55

6-
RUN apt-get update && \
7-
apt-get -y install --no-install-suggests --no-install-recommends \
8-
cmake libtool autoconf automake pkg-config \
9-
&& apt-get clean \
10-
&& rm -rf /var/lib/apt/lists/*
6+
RUN apt-get update \
7+
&& apt-get -y install --no-install-suggests --no-install-recommends \
8+
cmake \
9+
pkg-config \
10+
&& apt-get clean \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
1114

1215
# Static builds of dependencies
1316

1417
# libsodium
15-
RUN git clone --depth 1 --branch 1.0.18 https://github.com/jedisct1/libsodium libsodium
16-
WORKDIR $SRC/libsodium
17-
RUN ./autogen.sh && ./configure --enable-shared=no && make install
18-
WORKDIR $SRC
18+
RUN tar zxf <(curl -L https://github.com/jedisct1/libsodium/releases/download/1.0.20-RELEASE/libsodium-1.0.20.tar.gz) \
19+
&& cd libsodium-* \
20+
&& ./configure --enable-shared=no \
21+
&& make install \
22+
&& cd ..
1923

2024
# Copy your project's source code.
2125
COPY . $SRC/c-toxcore

.clusterfuzzlite/build.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
#!/bin/bash -eu
22

3-
FUZZ_TARGETS="bootstrap_fuzz_test toxsave_fuzz_test"
3+
FUZZ_TARGETS=(
4+
DHT_fuzz_test
5+
bootstrap_fuzz_test
6+
# e2e_fuzz_test
7+
forwarding_fuzz_test
8+
group_announce_fuzz_test
9+
group_moderation_fuzz_test
10+
net_crypto_fuzz_test
11+
tox_events_fuzz_test
12+
toxsave_fuzz_test
13+
)
414

515
# out of tree build
616
cd "$WORK"
@@ -12,11 +22,10 @@ cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER="$CC" \
1222
-DCMAKE_CXX_COMPILER="$CXX" \
1323
-DCMAKE_C_FLAGS="$CFLAGS" \
1424
-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
15-
-DCMAKE_EXE_LINKER_FLAGS="$LIB_FUZZING_ENGINE" \
1625
-DBUILD_TOXAV=OFF -DENABLE_SHARED=NO -DBUILD_FUZZ_TESTS=ON \
1726
-DDHT_BOOTSTRAP=OFF -DBOOTSTRAP_DAEMON=OFF "$SRC"/c-toxcore
1827

19-
for TARGET in $FUZZ_TARGETS; do
28+
for TARGET in "${FUZZ_TARGETS[@]}"; do
2029
# build fuzzer target
2130
cmake --build ./ --target "$TARGET"
2231

.github/scripts/flags-clang.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ add_cxx_flag -Wno-c99-extensions
6969
add_cxx_flag -Wno-old-style-cast
7070
# GTest does this.
7171
add_cxx_flag -Wno-global-constructors
72+
# Needed for some fuzzers.
73+
add_cxx_flag -Wno-exit-time-destructors
7274

7375
# Downgrade to warning so we still see it.
7476
add_flag -Wno-error=unreachable-code

.github/workflows/cflite_batch.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Derived from: https://google.github.io/clusterfuzzlite/running-clusterfuzzlite/github-actions/
22

33
name: ClusterFuzzLite batch fuzzing
4+
45
on:
56
schedule:
67
- cron: '0 6,8 * * *' # Run twice a day at low activity times
78
workflow_dispatch: # Manual trigger for testing
9+
810
permissions: read-all
11+
912
jobs:
1013
BatchFuzzing:
1114
runs-on: ubuntu-latest

.github/workflows/cflite_cron.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
workflow_dispatch: # Manual trigger for testing
88

99
permissions: read-all
10+
1011
jobs:
1112
Pruning:
1213
runs-on: ubuntu-latest
@@ -26,6 +27,7 @@ jobs:
2627
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/TokTok/toktok-fuzzer.git
2728
storage-repo-branch: master # Optional. Defaults to "main"
2829
storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
30+
2931
Coverage:
3032
runs-on: ubuntu-latest
3133
steps:
@@ -47,4 +49,3 @@ jobs:
4749
storage-repo: https://${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/TokTok/toktok-fuzzer.git
4850
storage-repo-branch: master # Optional. Defaults to "main"
4951
storage-repo-branch-coverage: gh-pages # Optional. Defaults to "gh-pages".
50-

.github/workflows/cflite_pr.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Derived from: https://google.github.io/clusterfuzzlite/running-clusterfuzzlite/github-actions/
2+
3+
name: ClusterFuzzLite pull request fuzzing
4+
5+
on:
6+
pull_request:
7+
types: [opened, synchronize]
8+
9+
jobs:
10+
Fuzzing:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
sanitizer:
16+
- address
17+
- undefined
18+
- memory
19+
steps:
20+
- name: Build Fuzzers (${{ matrix.sanitizer }})
21+
id: build
22+
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
23+
with:
24+
sanitizer: ${{ matrix.sanitizer }}
25+
- name: Run Fuzzers (${{ matrix.sanitizer }})
26+
id: run
27+
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
fuzz-seconds: 300 # 5 mins (total time, not per test)
31+
mode: 'code-change'
32+
sanitizer: ${{ matrix.sanitizer }}
33+
# Optional but recommended: For storing certain artifacts from fuzzing.
34+
# See later section on "Git repo for storage".
35+
storage-repo: https://github.com/TokTok/toktok-fuzzer.git
36+
storage-repo-branch: master # Optional. Defaults to "main"

testing/fuzzing/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function(fuzz_test target source_dir)
2020
endfunction()
2121

2222
fuzz_test(bootstrap .) # Fuzzes the bootstrap process
23-
fuzz_test(toxsave .) # Fuzzes the bootstrap process
23+
# TODO(iphydf): Fix this in the cmake build.
24+
# fuzz_test(e2e .) # Fuzzes an end-to-end connection
25+
fuzz_test(toxsave .) # Fuzzes tox_new and tox_get_savedata
2426

2527
fuzz_test(DHT ../../toxcore)
2628
fuzz_test(forwarding ../../toxcore)

testing/fuzzing/toxsave_fuzz_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void TestSaveDataLoading(Fuzz_Data &input)
2020
const size_t savedata_size = input.size();
2121
CONSUME_OR_RETURN(const uint8_t *savedata, input, savedata_size);
2222

23+
tox_options_set_experimental_groups_persistence(tox_options, true);
24+
2325
// pass test data to Tox
2426
tox_options_set_savedata_data(tox_options, savedata, savedata_size);
2527
tox_options_set_savedata_type(tox_options, TOX_SAVEDATA_TYPE_TOX_SAVE);

toxcore/forwarding_fuzz_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace {
1313
std::optional<std::tuple<IP_Port, IP_Port, const uint8_t *, size_t>> prepare(Fuzz_Data &input)
1414
{
1515
CONSUME_OR_RETURN_VAL(const uint8_t *ipp_packed, input, SIZE_IP_PORT, std::nullopt);
16-
IP_Port ipp;
16+
IP_Port ipp{};
1717
unpack_ip_port(&ipp, ipp_packed, SIZE_IP6, true);
1818

1919
CONSUME_OR_RETURN_VAL(const uint8_t *forwarder_packed, input, SIZE_IP_PORT, std::nullopt);
20-
IP_Port forwarder;
20+
IP_Port forwarder{};
2121
unpack_ip_port(&forwarder, forwarder_packed, SIZE_IP6, true);
2222

2323
// 2 bytes: size of the request
@@ -37,22 +37,22 @@ void TestSendForwardRequest(Fuzz_Data &input)
3737
const uint16_t chain_keys_size = chain_length * CRYPTO_PUBLIC_KEY_SIZE;
3838
CONSUME_OR_RETURN(const uint8_t *chain_keys, input, chain_keys_size);
3939

40-
auto prep = prepare(input);
40+
const auto prep = prepare(input);
4141
if (!prep.has_value()) {
4242
return;
4343
}
44-
auto [ipp, forwarder, data, data_size] = prep.value();
44+
const auto [ipp, forwarder, data, data_size] = prep.value();
4545

4646
// rest of the fuzz data is input for malloc and network
4747
Fuzz_System sys(input);
4848

49-
Ptr<Logger> logger(logger_new(sys.mem.get()), logger_kill);
49+
const Ptr<Logger> logger(logger_new(sys.mem.get()), logger_kill);
5050
if (logger == nullptr) {
5151
return;
5252
}
5353

54-
Ptr<Networking_Core> net(new_networking_ex(logger.get(), sys.mem.get(), sys.ns.get(), &ipp.ip,
55-
ipp.port, ipp.port + 100, nullptr),
54+
const Ptr<Networking_Core> net(new_networking_ex(logger.get(), sys.mem.get(), sys.ns.get(),
55+
&ipp.ip, ipp.port, ipp.port + 100, nullptr),
5656
kill_networking);
5757
if (net == nullptr) {
5858
return;
@@ -66,22 +66,22 @@ void TestForwardReply(Fuzz_Data &input)
6666
CONSUME1_OR_RETURN(const uint16_t, sendback_length, input);
6767
CONSUME_OR_RETURN(const uint8_t *sendback, input, sendback_length);
6868

69-
auto prep = prepare(input);
69+
const auto prep = prepare(input);
7070
if (!prep.has_value()) {
7171
return;
7272
}
73-
auto [ipp, forwarder, data, data_size] = prep.value();
73+
const auto [ipp, forwarder, data, data_size] = prep.value();
7474

7575
// rest of the fuzz data is input for malloc and network
7676
Fuzz_System sys(input);
7777

78-
Ptr<Logger> logger(logger_new(sys.mem.get()), logger_kill);
78+
const Ptr<Logger> logger(logger_new(sys.mem.get()), logger_kill);
7979
if (logger == nullptr) {
8080
return;
8181
}
8282

83-
Ptr<Networking_Core> net(new_networking_ex(logger.get(), sys.mem.get(), sys.ns.get(), &ipp.ip,
84-
ipp.port, ipp.port + 100, nullptr),
83+
const Ptr<Networking_Core> net(new_networking_ex(logger.get(), sys.mem.get(), sys.ns.get(),
84+
&ipp.ip, ipp.port, ipp.port + 100, nullptr),
8585
kill_networking);
8686
if (net == nullptr) {
8787
return;

0 commit comments

Comments
 (0)