Merge commit '9ddeea3d06045c8ae38cd2d6eed0fc2891c6e146'

This commit is contained in:
2023-12-15 15:21:40 +01:00
78 changed files with 892 additions and 415 deletions

View File

@ -1,8 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//tools:no_undefined.bzl", "cc_library")
package(features = ["layering_check"])
cc_library(
name = "bootstrap_node_packets",
srcs = ["bootstrap_node_packets.c"],

View File

@ -2,6 +2,9 @@
CHECKS="*"
# We don't use memcpy_s.
CHECKS="$CHECKS,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling"
# __attribute__((nonnull)) causes this warning on defensive null checks.
CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion"
CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare"
@ -57,6 +60,27 @@ CHECKS="$CHECKS,-readability-redundant-control-flow"
CHECKS="$CHECKS,-bugprone-narrowing-conversions"
CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions"
# Mistakenly thinks that
# const int a = 0, b = 1;
# assert(a < b);
# is a constant expression in C (it is in C++ though, which is probably why it's
# mistaken), suggesting to replace 'assert()' with 'static_assert()' in cases
# where that won't work.
#
# There are ways to make 'static_assert()' work, but they are rather annoying --
# they are somewhat ugly, hurting the readability, and some are error-prone:
#
# - Turning 'a' and 'b' into enum constants would make it work, but this falls
# apart if the enum types are compared against non-enums down the line
# error: enumerated and non-enumerated type in conditional expression [-Werror=extra]
#
# - Turning 'a' and 'b' into pre-processor macros is the only option left, but
# #defines and #undefs in the middle of a function hurt the readability and
# are less idiomatic than simply using 'const int'.
CHECKS="$CHECKS,-cert-dcl03-c"
CHECKS="$CHECKS,-hicpp-static-assert"
CHECKS="$CHECKS,-misc-static-assert"
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
# comment explaining why not.
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"

View File

@ -1,7 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
package(features = ["layering_check"])
cc_binary(
name = "bootstrap_daemon",
srcs = glob([

View File

@ -1,6 +1,6 @@
###########################################################
# Builder image: we compile the code here (static build)
FROM alpine:3.15.0 AS build
FROM alpine:3.18.5 AS build
RUN ["apk", "--no-cache", "add",\
"build-base",\
@ -62,7 +62,7 @@ RUN ["other/bootstrap_daemon/docker/get-nodes.py", "other/bootstrap_daemon/tox-b
###########################################################
# Final image build: this is what runs the bootstrap node
FROM debian:bullseye-slim
FROM debian:bookworm-slim
COPY --from=build /usr/local/bin/tox-bootstrapd /usr/local/bin/
COPY --from=build /src/c-toxcore/other/bootstrap_daemon/tox-bootstrapd.conf /etc/tox-bootstrapd.conf

View File

@ -1 +1 @@
b2996d73cab7c7453dc10ccf7ad733622558de3b1ad0db824a379cf96f500379 /usr/local/bin/tox-bootstrapd
5aac1df4d6c1de289e8e9f646d06099c84fd4d9b80d19f45e3254eec3ece2bff /usr/local/bin/tox-bootstrapd

View File

@ -3,7 +3,7 @@
set -eux
docker_build() {
docker build -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
DOCKER_BUILDKIT=1 docker build --progress=plain -f other/bootstrap_daemon/docker/Dockerfile -t toxchat/bootstrap-node .
}
# Run Docker build once. If it succeeds, we're good.
@ -12,12 +12,11 @@ if docker_build; then
fi
# We're not good. Run it again, but now capture the output.
OUTPUT=$(docker_build || true 2>&1)
OUTPUT=$(docker_build 2>&1 || true)
if echo "$OUTPUT" | grep '/usr/local/bin/tox-bootstrapd: FAILED'; then
# This is a checksum warning, so we need to update it.
IMAGE=$(echo "$OUTPUT" | grep '^ ---> [0-9a-f]*$' | grep -o '[0-9a-f]*$' | tail -n1)
docker run --rm "$IMAGE" sha256sum /usr/local/bin/tox-bootstrapd >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
echo "$OUTPUT" | grep -Eo '[0-9a-f]{64} /usr/local/bin/tox-bootstrapd' | tail -n1 >other/bootstrap_daemon/docker/tox-bootstrapd.sha256
fi
# Run once last time to complete the build.

View File

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2018 The TokTok team.
* Copyright © 2016-2023 The TokTok team.
* Copyright © 2014-2016 Tox project.
*/
@ -39,22 +39,28 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS);
log_write(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS);
uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS};
uint16_t default_ports[] = {DEFAULT_TCP_RELAY_PORTS};
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
log_write(LOG_LEVEL_INFO, "Port #%d: %u\n", i, default_ports[i]);
// Check to avoid calling malloc(0) later on
// NOLINTNEXTLINE, clang-tidy: error: suspicious comparison of 'sizeof(expr)' to a constant [bugprone-sizeof-expression,-warnings-as-errors]
static_assert(sizeof(default_ports) > 0, "At least one default TCP relay port should be provided");
const size_t default_ports_count = sizeof(default_ports)/sizeof(*default_ports);
for (size_t i = 0; i < default_ports_count; ++i) {
log_write(LOG_LEVEL_INFO, "Port #%zu: %u\n", i, default_ports[i]);
}
// similar procedure to the one of reading config file below
*tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t));
*tcp_relay_ports = (uint16_t *)malloc(default_ports_count * sizeof(uint16_t));
for (int i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; ++i) {
for (size_t i = 0; i < default_ports_count; ++i) {
(*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i];
if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT
|| (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) {
log_write(LOG_LEVEL_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i,
log_write(LOG_LEVEL_WARNING, "Port #%zu: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i,
(*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT);
continue;
}

View File

@ -1,5 +1,5 @@
/* SPDX-License-Identifier: GPL-3.0-or-later
* Copyright © 2016-2018 The TokTok team.
* Copyright © 2016-2023 The TokTok team.
* Copyright © 2014-2016 Tox project.
*/
@ -19,8 +19,7 @@
#define DEFAULT_ENABLE_IPV4_FALLBACK 1 // 1 - true, 0 - false
#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false
#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false
#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly
#define DEFAULT_TCP_RELAY_PORTS_COUNT 3
#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports
#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false
#define DEFAULT_MOTD DAEMON_NAME

View File

@ -375,6 +375,7 @@ int main(int argc, char *argv[])
if (!onion) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox Onion. Exiting.\n");
kill_gca(group_announce);
kill_announcements(announce);
kill_forwarding(forwarding);
kill_dht(dht);
@ -454,7 +455,7 @@ int main(int argc, char *argv[])
if (tcp_relay_port_count == 0) {
log_write(LOG_LEVEL_ERROR, "No TCP relay ports read. Exiting.\n");
kill_onion_announce(onion_a);
kill_gca(group_announce);
kill_gca(group_announce);
kill_announcements(announce);
kill_forwarding(forwarding);
kill_onion(onion);

View File

@ -1,7 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
package(features = ["-layering_check"])
go_library(
name = "go_default_library",
srcs = ["websockify.go"],

View File

@ -0,0 +1,6 @@
FROM toxchat/alpine-s390x:latest
WORKDIR /work/c-toxcore
COPY . /work/c-toxcore/
RUN [".github/scripts/cmake-alpine-s390x"]

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eux
BUILD=alpine-s390x
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -1,3 +1,5 @@
#!/bin/sh
docker build -t toxchat/c-toxcore:autotools -f other/docker/autotools/Dockerfile .
set -eux
BUILD=autotools
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -5,4 +5,4 @@ if [ "$1" = "-u" ]; then
docker pull toxchat/haskell:hs-cimple
docker build -t toxchat/cimplefmt -f other/docker/cimplefmt/Dockerfile .
fi
docker run --rm -v "$PWD:/work" toxchat/cimplefmt "$@"
docker run --name toxcore-cimplefmt --rm -v "$PWD:/work" toxchat/cimplefmt "$@"

View File

@ -3,4 +3,4 @@
SANITIZER="${1:-asan}"
docker build -t toxchat/c-toxcore:circleci other/docker/circleci
docker run --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER"
docker run --name toxcore-circleci --rm -it -v "$PWD:/c-toxcore" toxchat/c-toxcore:circleci "$SANITIZER"

View File

@ -0,0 +1,30 @@
FROM toxchat/compcert:latest
WORKDIR /work
COPY auto_tests/ /work/auto_tests/
COPY testing/ /work/testing/
COPY toxav/ /work/toxav/
COPY toxcore/ /work/toxcore/
COPY toxencryptsave/ /work/toxencryptsave/
COPY third_party/ /work/third_party/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN ccomp \
-o send_message_test \
-Wall -Werror \
-Wno-c11-extensions \
-Wno-unknown-pragmas \
-Wno-unused-variable \
-fstruct-passing -fno-unprototyped -g \
auto_tests/auto_test_support.c \
auto_tests/send_message_test.c \
testing/misc_tools.c \
toxav/*.c \
toxcore/*.c \
toxcore/*/*.c \
toxencryptsave/*.c \
third_party/cmp/*.c \
-D__COMPCERT__ -DDISABLE_VLA -Dinline= \
-lpthread $(pkg-config --cflags --libs libsodium opus vpx) \
&& ./send_message_test | grep 'tox clients connected'

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eux
BUILD=compcert
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -4,4 +4,4 @@ set -eux
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
docker build -t toxchat/c-toxcore:coverage other/docker/coverage
docker run --rm -it -p "28192:80" toxchat/c-toxcore:coverage
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage

View File

@ -3,4 +3,4 @@
set -eux
docker build -t toxchat/c-toxcore:docs -f other/docker/doxygen/Dockerfile .
docker run --rm -it -p "28192:80" toxchat/c-toxcore:docs
docker run --name toxcore-docs --rm -it -p "28192:80" toxchat/c-toxcore:docs

View File

@ -0,0 +1,6 @@
FROM toxchat/freebsd:latest
WORKDIR /work/c-toxcore
COPY . /work/c-toxcore/
RUN [".github/scripts/cmake-freebsd"]

View File

@ -0,0 +1,5 @@
#!/bin/sh
set -eux
BUILD=freebsd
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -1,3 +1,5 @@
#!/bin/sh
docker build -f other/docker/misra/Dockerfile .
set -eux
BUILD=misra
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -3,7 +3,7 @@
set -eux
docker build -t toxchat/c-toxcore:perf -f other/docker/perf/Dockerfile .
docker run --privileged --rm -it \
docker run --name toxcore-perf --privileged --rm -it \
-v "$PWD:/work/c-toxcore" \
toxchat/c-toxcore:perf \
"$@"

View File

@ -1,4 +1,4 @@
FROM ubuntu:20.04
FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
@ -17,6 +17,9 @@ COPY testing/ /work/testing/
COPY toxav/ /work/toxav/
COPY toxcore/ /work/toxcore/
COPY toxencryptsave/ /work/toxencryptsave/
COPY third_party/ /work/third_party/
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN tcc \
-Dinline=static \
@ -31,9 +34,9 @@ RUN tcc \
toxcore/*/*.c \
toxencryptsave/*.c \
third_party/cmp/*.c \
$(pkg-config --cflags --libs libsodium opus vpx)
$(pkg-config --cflags --libs libsodium opus vpx) \
&& ./send_message_test | grep 'tox clients connected'
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
COPY other/make_single_file /work/other/
RUN \
other/make_single_file \
@ -44,4 +47,5 @@ RUN \
-o send_message_test \
-Wall -Werror \
-bench -g \
$(pkg-config --cflags --libs libsodium opus vpx)
$(pkg-config --cflags --libs libsodium opus vpx) \
&& ./send_message_test | grep 'tox clients connected'

View File

@ -1,5 +1,5 @@
#!/bin/sh
set -eux
docker build -t toxchat/c-toxcore:tcc -f other/docker/tcc/Dockerfile .
BUILD=tcc
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -1,3 +1,5 @@
#!/bin/sh
docker build -f other/docker/tokstyle/Dockerfile .
set -eux
BUILD=tokstyle
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .

View File

@ -1,7 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
package(features = ["layering_check"])
#cc_binary(
# name = "cracker",
# testonly = 1,

View File

@ -73,10 +73,15 @@ static void print_information(Tox *tox)
int length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam);
nospam_str[length] = '\0';
uint8_t *name = (uint8_t *)malloc(tox_self_get_name_size(tox) + 1);
assert(name != nullptr);
size_t name_size = tox_self_get_name_size(tox);
uint8_t *name = (uint8_t *)malloc(name_size + 1);
if (!name) {
return;
}
tox_self_get_name(tox, name);
name[tox_self_get_name_size(tox)] = '\0';
name[name_size] = '\0';
printf("INFORMATION\n");
printf("----------------------------------\n");
@ -86,6 +91,8 @@ static void print_information(Tox *tox)
printf("Status message: %s.\n", GENERATED_STATUS_MESSAGE);
printf("Number of friends: %zu.\n", tox_self_get_friend_list_size(tox));
printf("----------------------------------\n");
free(name);
}
int main(int argc, char *argv[])

View File

@ -1,7 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
package(features = ["layering_check"])
go_library(
name = "go_default_library",
srcs = ["proxy_server.go"],