forked from Green-Sky/tomato
Squashed 'external/toxcore/c-toxcore/' changes from e58eb27a8..1828c5356
1828c5356 fix(toxav): remove extra copy of video frame on encode b66b8ded6 refactor: improve group stability, moderation determinism, and DHT dual-stack handling 4fbd7c10a fix(toxav): fix heap buffer overflow in RTP video packet handling 809fe8c78 refactor(tox): make the `#define` consts int literals. 50d242a37 refactor(toxav): improve MSI safety and testability da1c13a2f fix(toxav): harden video processing and fix large frame handling 472825288 fix(toxav): fix multiple logic bugs in audio module dc963d9a9 fix(toxav): fix multiple bugs in bandwidth controller and add tests 3bf5778ef refactor(toxav): split out RTP module and add exhaustive unit tests b79b7d436 fix(autotools): add tox_log_level.h to public headers list ea2e34ff2 chore: Disable cirrus. We're out of quota again. b449ea2ed chore(ci): update azure runner image to windows-2022 windows-2019 is EOL e115b136d refactor: Make add_to_list non-recursive. REVERT: e58eb27a8 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff. git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 1828c5356b2daf1d5f680854e776d74b181d268c
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "group_moderation.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@@ -23,6 +24,30 @@
|
||||
#include "network.h"
|
||||
#include "util.h"
|
||||
|
||||
static int compare_signatures(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, SIGNATURE_SIZE);
|
||||
}
|
||||
|
||||
static int compare_sig_pks(const void *a, const void *b)
|
||||
{
|
||||
return memcmp(a, b, SIG_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
static int compare_sanctions(const void *a, const void *b)
|
||||
{
|
||||
const Mod_Sanction *sa = (const Mod_Sanction *)a;
|
||||
const Mod_Sanction *sb = (const Mod_Sanction *)b;
|
||||
return memcmp(sa->signature, sb->signature, SIGNATURE_SIZE);
|
||||
}
|
||||
|
||||
static int compare_mod_pointers(const void *a, const void *b)
|
||||
{
|
||||
const uint8_t *const *mod_a = (const uint8_t *const *)a;
|
||||
const uint8_t *const *mod_b = (const uint8_t *const *)b;
|
||||
return memcmp(*mod_a, *mod_b, SIG_PUBLIC_KEY_SIZE);
|
||||
}
|
||||
|
||||
static_assert(MOD_SANCTIONS_CREDS_SIZE <= MAX_PACKET_SIZE_NO_HEADERS,
|
||||
"MOD_SANCTIONS_CREDS_SIZE must be <= the maximum allowed payload size");
|
||||
static_assert(MOD_MAX_NUM_SANCTIONS * MOD_SANCTION_PACKED_SIZE + MOD_SANCTIONS_CREDS_SIZE <= MAX_PACKET_SIZE_NO_HEADERS,
|
||||
@@ -34,6 +59,7 @@ static_assert(MOD_MAX_NUM_MODERATORS <= MOD_MAX_NUM_MODERATORS_LIMIT,
|
||||
static_assert(MOD_MAX_NUM_SANCTIONS <= MOD_MAX_NUM_SANCTIONS_LIMIT,
|
||||
"MOD_MAX_NUM_SANCTIONS must be <= MOD_MAX_NUM_SANCTIONS_LIMIT");
|
||||
|
||||
/** @brief Returns the size in bytes of the packed moderation list. */
|
||||
uint16_t mod_list_packed_size(const Moderation *_Nonnull moderation)
|
||||
{
|
||||
return moderation->num_mods * MOD_LIST_ENTRY_SIZE;
|
||||
@@ -76,6 +102,8 @@ int mod_list_unpack(Moderation *_Nonnull moderation, const uint8_t *_Nonnull dat
|
||||
moderation->mod_list = tmp_list;
|
||||
moderation->num_mods = num_mods;
|
||||
|
||||
qsort(moderation->mod_list, moderation->num_mods, sizeof(uint8_t *), compare_mod_pointers);
|
||||
|
||||
return unpacked_len;
|
||||
}
|
||||
|
||||
@@ -110,6 +138,8 @@ bool mod_list_make_hash(const Moderation *_Nonnull moderation, uint8_t *_Nonnull
|
||||
|
||||
mod_list_pack(moderation, data);
|
||||
|
||||
qsort(data, moderation->num_mods, SIG_PUBLIC_KEY_SIZE, compare_sig_pks);
|
||||
|
||||
mod_list_get_data_hash(hash, data, data_buf_size);
|
||||
|
||||
mem_delete(moderation->mem, data);
|
||||
@@ -176,6 +206,8 @@ bool mod_list_remove_index(Moderation *_Nonnull moderation, uint16_t index)
|
||||
|
||||
moderation->mod_list = tmp_list;
|
||||
|
||||
qsort(moderation->mod_list, moderation->num_mods, sizeof(uint8_t *), compare_mod_pointers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -221,6 +253,8 @@ bool mod_list_add_entry(Moderation *_Nonnull moderation, const uint8_t *_Nonnull
|
||||
tmp_list[moderation->num_mods] = entry;
|
||||
++moderation->num_mods;
|
||||
|
||||
qsort(moderation->mod_list, moderation->num_mods, sizeof(uint8_t *), compare_mod_pointers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -430,6 +464,8 @@ static bool sanctions_list_make_hash(const Memory *_Nonnull mem, const Mod_Sanct
|
||||
memcpy(&data[i * SIGNATURE_SIZE], sanctions[i].signature, SIGNATURE_SIZE);
|
||||
}
|
||||
|
||||
qsort(data, num_sanctions, SIGNATURE_SIZE, compare_signatures);
|
||||
|
||||
memcpy(&data[sig_data_size], &new_version, sizeof(uint32_t));
|
||||
crypto_sha256(hash, data, data_buf_size);
|
||||
|
||||
@@ -594,6 +630,8 @@ static bool sanctions_apply_new(Moderation *_Nonnull moderation, Mod_Sanction *_
|
||||
moderation->sanctions_creds = *new_creds;
|
||||
}
|
||||
|
||||
qsort(new_sanctions, num_sanctions, sizeof(Mod_Sanction), compare_sanctions);
|
||||
|
||||
sanctions_list_cleanup(moderation);
|
||||
moderation->sanctions = new_sanctions;
|
||||
moderation->num_sanctions = num_sanctions;
|
||||
@@ -805,7 +843,8 @@ bool sanctions_list_make_entry(Moderation *_Nonnull moderation, const uint8_t *_
|
||||
|
||||
memcpy(sanction->setter_public_sig_key, moderation->self_public_sig_key, SIG_PUBLIC_KEY_SIZE);
|
||||
|
||||
sanction->time_set = (uint64_t)time(nullptr);
|
||||
/* Use a stable non-zero value to ensure deterministic signatures and hashes. */
|
||||
sanction->time_set = 1;
|
||||
sanction->type = type;
|
||||
|
||||
if (!sanctions_list_sign_entry(moderation, sanction)) {
|
||||
|
||||
Reference in New Issue
Block a user