Skip to content

Commit 4f116ad

Browse files
authored
Merge branch 'master' into zoff99/large_pkt_incoming
2 parents 80ac793 + d6d67d5 commit 4f116ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+581
-334
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
analysis:
1717
strategy:
1818
matrix:
19-
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, infer, misra, tcc, tokstyle]
19+
tool: [autotools, clang-tidy, compcert, cppcheck, doxygen, goblint, infer, misra, tcc, tokstyle]
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Set up Docker Buildx

auto_tests/TCP_test.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ static uint16_t ports[NUM_PORTS] = {13215, 33445, 25643};
4545

4646
static void test_basic(void)
4747
{
48-
const Random *rng = system_random();
48+
const Random *rng = os_random();
4949
ck_assert(rng != nullptr);
50-
const Network *ns = system_network();
50+
const Network *ns = os_network();
5151
ck_assert(ns != nullptr);
52-
const Memory *mem = system_memory();
52+
const Memory *mem = os_memory();
5353
ck_assert(mem != nullptr);
5454

5555
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@@ -266,13 +266,14 @@ static void kill_tcp_con(struct sec_TCP_con *con)
266266
static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP_con *con, const uint8_t *data,
267267
uint16_t length)
268268
{
269-
VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE);
269+
const uint16_t packet_size = sizeof(uint16_t) + length + CRYPTO_MAC_SIZE;
270+
VLA(uint8_t, packet, packet_size);
270271

271272
uint16_t c_length = net_htons(length + CRYPTO_MAC_SIZE);
272273
memcpy(packet, &c_length, sizeof(uint16_t));
273274
int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t));
274275

275-
if ((unsigned int)len != (SIZEOF_VLA(packet) - sizeof(uint16_t))) {
276+
if ((unsigned int)len != (packet_size - sizeof(uint16_t))) {
276277
return -1;
277278
}
278279

@@ -282,7 +283,7 @@ static int write_packet_tcp_test_connection(const Logger *logger, struct sec_TCP
282283
localhost.ip = get_loopback();
283284
localhost.port = 0;
284285

285-
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, SIZEOF_VLA(packet), &localhost) == SIZEOF_VLA(packet),
286+
ck_assert_msg(net_send(con->ns, logger, con->sock, packet, packet_size, &localhost) == packet_size,
286287
"Failed to send a packet.");
287288
return 0;
288289
}
@@ -303,11 +304,11 @@ static int read_packet_sec_tcp(const Logger *logger, struct sec_TCP_con *con, ui
303304

304305
static void test_some(void)
305306
{
306-
const Random *rng = system_random();
307+
const Random *rng = os_random();
307308
ck_assert(rng != nullptr);
308-
const Network *ns = system_network();
309+
const Network *ns = os_network();
309310
ck_assert(ns != nullptr);
310-
const Memory *mem = system_memory();
311+
const Memory *mem = os_memory();
311312
ck_assert(mem != nullptr);
312313

313314
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@@ -498,11 +499,11 @@ static int oob_data_callback(void *object, const uint8_t *public_key, const uint
498499

499500
static void test_client(void)
500501
{
501-
const Random *rng = system_random();
502+
const Random *rng = os_random();
502503
ck_assert(rng != nullptr);
503-
const Network *ns = system_network();
504+
const Network *ns = os_network();
504505
ck_assert(ns != nullptr);
505-
const Memory *mem = system_memory();
506+
const Memory *mem = os_memory();
506507
ck_assert(mem != nullptr);
507508

508509
Logger *logger = logger_new();
@@ -581,7 +582,7 @@ static void test_client(void)
581582
do_tcp_connection(logger, mono_time, conn2, nullptr);
582583
c_sleep(50);
583584

584-
uint8_t data[5] = {1, 2, 3, 4, 5};
585+
const uint8_t data[5] = {1, 2, 3, 4, 5};
585586
memcpy(oob_pubkey, f2_public_key, CRYPTO_PUBLIC_KEY_SIZE);
586587
send_oob_packet(logger, conn2, f_public_key, data, 5);
587588
send_routing_request(logger, conn, f2_public_key);
@@ -632,11 +633,11 @@ static void test_client(void)
632633
// Test how the client handles servers that don't respond.
633634
static void test_client_invalid(void)
634635
{
635-
const Random *rng = system_random();
636+
const Random *rng = os_random();
636637
ck_assert(rng != nullptr);
637-
const Network *ns = system_network();
638+
const Network *ns = os_network();
638639
ck_assert(ns != nullptr);
639-
const Memory *mem = system_memory();
640+
const Memory *mem = os_memory();
640641
ck_assert(mem != nullptr);
641642

642643
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@@ -711,11 +712,11 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
711712

712713
static void test_tcp_connection(void)
713714
{
714-
const Random *rng = system_random();
715+
const Random *rng = os_random();
715716
ck_assert(rng != nullptr);
716-
const Network *ns = system_network();
717+
const Network *ns = os_network();
717718
ck_assert(ns != nullptr);
718-
const Memory *mem = system_memory();
719+
const Memory *mem = os_memory();
719720
ck_assert(mem != nullptr);
720721

721722
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
@@ -824,11 +825,11 @@ static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigne
824825

825826
static void test_tcp_connection2(void)
826827
{
827-
const Random *rng = system_random();
828+
const Random *rng = os_random();
828829
ck_assert(rng != nullptr);
829-
const Network *ns = system_network();
830+
const Network *ns = os_network();
830831
ck_assert(ns != nullptr);
831-
const Memory *mem = system_memory();
832+
const Memory *mem = os_memory();
832833
ck_assert(mem != nullptr);
833834

834835
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);

auto_tests/announce_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static void test_bucketnum(void)
1515
{
16-
const Random *rng = system_random();
16+
const Random *rng = os_random();
1717
ck_assert(rng != nullptr);
1818
uint8_t key1[CRYPTO_PUBLIC_KEY_SIZE], key2[CRYPTO_PUBLIC_KEY_SIZE];
1919
random_bytes(rng, key1, sizeof(key1));
@@ -50,11 +50,11 @@ static void test_announce_data(void *object, const uint8_t *data, uint16_t lengt
5050

5151
static void test_store_data(void)
5252
{
53-
const Random *rng = system_random();
53+
const Random *rng = os_random();
5454
ck_assert(rng != nullptr);
55-
const Network *ns = system_network();
55+
const Network *ns = os_network();
5656
ck_assert(ns != nullptr);
57-
const Memory *mem = system_memory();
57+
const Memory *mem = os_memory();
5858
ck_assert(mem != nullptr);
5959

6060
Logger *log = logger_new();

auto_tests/auto_test_support.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTo
335335
}
336336
}
337337

338-
static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
338+
static void bootstrap_autotoxes(const Tox_Options *options, uint32_t tox_count, const Run_Auto_Options *autotest_opts,
339339
AutoTox *autotoxes)
340340
{
341341
const bool udp_enabled = options != nullptr ? tox_options_get_udp_enabled(options) : true;
@@ -363,7 +363,9 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count,
363363
}
364364
}
365365

366-
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, void test(AutoTox *autotoxes),
366+
typedef void autotox_test_cb(AutoTox *autotoxes);
367+
368+
void run_auto_test(struct Tox_Options *options, uint32_t tox_count, autotox_test_cb *test,
367369
uint32_t state_size, Run_Auto_Options *autotest_opts)
368370
{
369371
printf("initialising %u toxes\n", tox_count);

auto_tests/conference_av_test.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static void handle_conference_connected(
108108
}
109109

110110
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
111-
bool *disconnected)
111+
const bool *disconnected)
112112
{
113113
uint32_t num_disconnected = 0;
114114

@@ -177,7 +177,7 @@ static bool all_connected_to_group(uint32_t tox_count, AutoTox *autotoxes)
177177
* returns a random index at which a list of booleans is false
178178
* (some such index is required to exist)
179179
*/
180-
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
180+
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
181181
{
182182
uint32_t index;
183183

@@ -197,7 +197,7 @@ static bool all_got_audio(AutoTox *autotoxes, const bool *disabled)
197197
}
198198

199199
for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) {
200-
State *state = (State *)autotoxes[i].state;
200+
const State *state = (const State *)autotoxes[i].state;
201201

202202
if (disabled[i] ^ (state->received_audio_num
203203
!= NUM_AV_GROUP_TOX - num_disabled - 1)) {
@@ -303,7 +303,7 @@ static void do_audio(AutoTox *autotoxes, uint32_t iterations)
303303

304304
static void run_conference_tests(AutoTox *autotoxes)
305305
{
306-
const Random *rng = system_random();
306+
const Random *rng = os_random();
307307
ck_assert(rng != nullptr);
308308
bool disabled[NUM_AV_GROUP_TOX] = {0};
309309

auto_tests/conference_invite_merge_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void handle_conference_connected(
4040
state->connected = true;
4141
}
4242

43-
static void wait_connected(AutoTox *autotoxes, AutoTox *autotox, uint32_t friendnumber)
43+
static void wait_connected(AutoTox *autotoxes, const AutoTox *autotox, uint32_t friendnumber)
4444
{
4545
do {
4646
iterate_all_wait(autotoxes, NUM_INVITE_MERGE_TOX, ITERATION_INTERVAL);

auto_tests/conference_simple_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static void handle_conference_connected(Tox *tox, const Tox_Event_Conference_Con
116116
}
117117

118118
static void iterate_one(
119-
Tox *tox, State *state, Tox_Dispatch *dispatch)
119+
Tox *tox, State *state, const Tox_Dispatch *dispatch)
120120
{
121121
Tox_Err_Events_Iterate err;
122122
Tox_Events *events = tox_events_iterate(tox, true, &err);
@@ -129,7 +129,7 @@ static void iterate3_wait(
129129
Tox *tox1, State *state1,
130130
Tox *tox2, State *state2,
131131
Tox *tox3, State *state3,
132-
Tox_Dispatch *dispatch, int interval)
132+
const Tox_Dispatch *dispatch, int interval)
133133
{
134134
iterate_one(tox1, state1, dispatch);
135135
iterate_one(tox2, state2, dispatch);

auto_tests/conference_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static void handle_conference_message(
9797
}
9898

9999
static bool toxes_are_disconnected_from_group(uint32_t tox_count, AutoTox *autotoxes,
100-
bool *disconnected)
100+
const bool *disconnected)
101101
{
102102
uint32_t num_disconnected = 0;
103103

@@ -179,7 +179,7 @@ static bool names_propagated(uint32_t tox_count, AutoTox *autotoxes)
179179
* returns a random index at which a list of booleans is false
180180
* (some such index is required to exist)
181181
*/
182-
static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length)
182+
static uint32_t random_false_index(const Random *rng, const bool *list, const uint32_t length)
183183
{
184184
uint32_t index;
185185

@@ -192,7 +192,7 @@ static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t
192192

193193
static void run_conference_tests(AutoTox *autotoxes)
194194
{
195-
const Random *rng = system_random();
195+
const Random *rng = os_random();
196196
ck_assert(rng != nullptr);
197197
/* disabling name change propagation check for now, as it occasionally
198198
* fails due to disconnections too short to trigger freezing */

auto_tests/crypto_test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static void test_fast_known(void)
125125

126126
static void test_endtoend(void)
127127
{
128-
const Random *rng = system_random();
128+
const Random *rng = os_random();
129129
ck_assert(rng != nullptr);
130130

131131
// Test 100 random messages and keypairs
@@ -192,7 +192,7 @@ static void test_endtoend(void)
192192

193193
static void test_large_data(void)
194194
{
195-
const Random *rng = system_random();
195+
const Random *rng = os_random();
196196
ck_assert(rng != nullptr);
197197
uint8_t k[CRYPTO_SHARED_KEY_SIZE];
198198
uint8_t n[CRYPTO_NONCE_SIZE];
@@ -236,7 +236,7 @@ static void test_large_data(void)
236236

237237
static void test_large_data_symmetric(void)
238238
{
239-
const Random *rng = system_random();
239+
const Random *rng = os_random();
240240
ck_assert(rng != nullptr);
241241
uint8_t k[CRYPTO_SYMMETRIC_KEY_SIZE];
242242

@@ -271,10 +271,10 @@ static void test_large_data_symmetric(void)
271271

272272
static void test_very_large_data(void)
273273
{
274-
const Random *rng = system_random();
274+
const Random *rng = os_random();
275275
ck_assert(rng != nullptr);
276276

277-
uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
277+
const uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
278278
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
279279
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
280280
crypto_new_keypair(rng, pk, sk);
@@ -316,7 +316,7 @@ static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
316316

317317
static void test_increment_nonce(void)
318318
{
319-
const Random *rng = system_random();
319+
const Random *rng = os_random();
320320
ck_assert(rng != nullptr);
321321

322322
uint8_t n[CRYPTO_NONCE_SIZE];

auto_tests/encryptsave_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void test_keys(void)
168168
ck_assert(encrypted2a != nullptr);
169169
uint8_t *in_plaintext2a = (uint8_t *)malloc(plaintext_length2a);
170170
ck_assert(in_plaintext2a != nullptr);
171-
const Random *rng = system_random();
171+
const Random *rng = os_random();
172172
ck_assert(rng != nullptr);
173173
random_bytes(rng, in_plaintext2a, plaintext_length2a);
174174
ret = tox_pass_encrypt(in_plaintext2a, plaintext_length2a, key_char, 12, encrypted2a, &encerr);

0 commit comments

Comments
 (0)