Skip to content

Commit 710eb67

Browse files
committed
fix: Correctly pass extended public keys to group moderation code.
It happens to work, but isn't clean, and static analysers found this (SonarCloud and Coverity both detected this).
1 parent 021db70 commit 710eb67

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

toxcore/group_chats.c

+13-12
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ non_null() static bool broadcast_gc_mod_list(const GC_Chat *chat);
961961
non_null() static bool broadcast_gc_shared_state(const GC_Chat *chat);
962962
non_null() static bool update_gc_sanctions_list(GC_Chat *chat, const uint8_t *public_sig_key);
963963
non_null() static bool update_gc_topic(GC_Chat *chat, const uint8_t *public_sig_key);
964-
non_null() static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_pk,
964+
non_null() static bool send_gc_set_observer(const GC_Chat *chat, const Extended_Public_Key *target_ext_pk,
965965
const uint8_t *sanction_data, uint16_t length, bool add_obs);
966966

967967
/** Returns true if peer designated by `peer_number` is in the sanctions list as an observer. */
@@ -1119,7 +1119,7 @@ static bool prune_gc_mod_list(GC_Chat *chat)
11191119
non_null()
11201120
static bool prune_gc_sanctions_list_inner(
11211121
GC_Chat *chat, const Mod_Sanction *sanction,
1122-
const uint8_t target_ext_pk[ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE])
1122+
const Extended_Public_Key *target_ext_pk)
11231123
{
11241124
if (!sanctions_list_remove_observer(&chat->moderation, sanction->target_public_enc_key, nullptr)) {
11251125
LOGGER_WARNING(chat->log, "Failed to remove entry from observer list");
@@ -1159,10 +1159,10 @@ static bool prune_gc_sanctions_list(GC_Chat *chat)
11591159

11601160
if (peer_number == -1) {
11611161
const Mod_Sanction *sanction = &chat->moderation.sanctions[i];
1162-
uint8_t target_ext_pk[ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE];
1163-
memcpy(target_ext_pk, sanction->target_public_enc_key, ENC_PUBLIC_KEY_SIZE);
1164-
memcpy(target_ext_pk + ENC_PUBLIC_KEY_SIZE, sanction->setter_public_sig_key, SIG_PUBLIC_KEY_SIZE);
1165-
return prune_gc_sanctions_list_inner(chat, sanction, target_ext_pk);
1162+
Extended_Public_Key target_ext_pk;
1163+
memcpy(target_ext_pk.enc, sanction->target_public_enc_key, ENC_PUBLIC_KEY_SIZE);
1164+
memcpy(target_ext_pk.sig, sanction->setter_public_sig_key, SIG_PUBLIC_KEY_SIZE);
1165+
return prune_gc_sanctions_list_inner(chat, sanction, &target_ext_pk);
11661166
}
11671167
}
11681168

@@ -4457,10 +4457,10 @@ static int handle_gc_set_observer(const GC_Session *c, GC_Chat *chat, uint32_t p
44574457
* Returns true on success.
44584458
*/
44594459
non_null()
4460-
static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_pk, const uint8_t *sanction_data,
4461-
uint16_t length, bool add_obs)
4460+
static bool send_gc_set_observer(const GC_Chat *chat, const Extended_Public_Key *target_ext_pk,
4461+
const uint8_t *sanction_data, uint16_t length, bool add_obs)
44624462
{
4463-
const uint16_t packet_len = 1 + EXT_PUBLIC_KEY_SIZE + length;
4463+
const uint16_t packet_len = 1 + ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE + length;
44644464
uint8_t *packet = (uint8_t *)malloc(packet_len);
44654465

44664466
if (packet == nullptr) {
@@ -4469,8 +4469,9 @@ static bool send_gc_set_observer(const GC_Chat *chat, const uint8_t *target_ext_
44694469

44704470
net_pack_bool(&packet[0], add_obs);
44714471

4472-
memcpy(packet + 1, target_ext_pk, EXT_PUBLIC_KEY_SIZE);
4473-
memcpy(packet + 1 + EXT_PUBLIC_KEY_SIZE, sanction_data, length);
4472+
memcpy(packet + 1, target_ext_pk->enc, ENC_PUBLIC_KEY_SIZE);
4473+
memcpy(packet + 1 + ENC_PUBLIC_KEY_SIZE, target_ext_pk->sig, SIG_PUBLIC_KEY_SIZE);
4474+
memcpy(packet + 1 + ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE, sanction_data, length);
44744475

44754476
if (!send_gc_broadcast_message(chat, packet, packet_len, GM_SET_OBSERVER)) {
44764477
free(packet);
@@ -4557,7 +4558,7 @@ static bool mod_gc_set_observer(GC_Chat *chat, uint32_t peer_number, bool add_ob
45574558

45584559
update_gc_peer_roles(chat);
45594560

4560-
return send_gc_set_observer(chat, gconn->addr.public_key.enc, sanction_data, length, add_obs);
4561+
return send_gc_set_observer(chat, &gconn->addr.public_key, sanction_data, length, add_obs);
45614562
}
45624563

45634564
/** @brief Sets the role of `peer_number` to `new_role`. If necessary this function will first

0 commit comments

Comments
 (0)