Skip to content

Commit

Permalink
Merge b3889f0 into 08ff19a
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jul 8, 2018
2 parents 08ff19a + b3889f0 commit 3a5c7c9
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions toxav/groupav.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,9 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_
return -1;
}

uint16_t sequnum;
memcpy(&sequnum, packet, sizeof(sequnum));
pk->sequnum = net_ntohs(sequnum);
net_unpack_u16(packet, &pk->sequnum);
pk->length = length - sizeof(uint16_t);
memcpy(pk->data, packet + sizeof(uint16_t), length - sizeof(uint16_t));
memcpy(pk->data, packet + sizeof(uint16_t), pk->length);

if (queue(peer_av->buffer, pk) == -1) {
free(pk);
Expand Down Expand Up @@ -503,19 +501,26 @@ int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber
*/
static int send_audio_packet(Group_Chats *g_c, uint32_t groupnumber, uint8_t *packet, uint16_t length)
{
if (!length) {
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE - 1 - sizeof(uint16_t)) {
return -1;
}

Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber);
VLA(uint8_t, data, 1 + sizeof(uint16_t) + length);
data[0] = GROUP_AUDIO_PACKET_ID;
const uint16_t plen = 1 + sizeof(uint16_t) + length;

Group_AV *const group_av = (Group_AV *)group_get_object(g_c, groupnumber);

if (!group_av) {
return -1;
}

uint8_t data[MAX_CRYPTO_DATA_SIZE];
uint8_t *ptr = data;
*ptr++ = GROUP_AUDIO_PACKET_ID;

uint16_t sequnum = net_htons(group_av->audio_sequnum);
memcpy(data + 1, &sequnum, sizeof(sequnum));
memcpy(data + 1 + sizeof(sequnum), packet, length);
ptr += net_pack_u16(ptr, group_av->audio_sequnum);
memcpy(ptr, packet, length);

if (send_group_lossy_packet(g_c, groupnumber, data, SIZEOF_VLA(data)) == -1) {
if (send_group_lossy_packet(g_c, groupnumber, data, plen) == -1) {
return -1;
}

Expand Down

0 comments on commit 3a5c7c9

Please sign in to comment.