diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-07-07 17:01:22 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-07-08 13:59:37 +0000 |
commit | b3889f0f052b450225eeb02826efcfea82ae9590 (patch) | |
tree | ba6f9523a4cfbf906851576d3bc7c6981fa45b31 /toxav/groupav.c | |
parent | 08ff19a63b487cbcaac971615bcc0b804e289820 (diff) |
Remove VLA usage from `send_audio_packet`.
Also use `net_pack_u16` in that function instead of manual ntohs+memcpy
and `net_unpack_u16` in its receiving counterpart.
Diffstat (limited to 'toxav/groupav.c')
-rw-r--r-- | toxav/groupav.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/toxav/groupav.c b/toxav/groupav.c index 8772838e..8936801a 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c | |||
@@ -406,11 +406,9 @@ static int handle_group_audio_packet(void *object, uint32_t groupnumber, uint32_ | |||
406 | return -1; | 406 | return -1; |
407 | } | 407 | } |
408 | 408 | ||
409 | uint16_t sequnum; | 409 | net_unpack_u16(packet, &pk->sequnum); |
410 | memcpy(&sequnum, packet, sizeof(sequnum)); | ||
411 | pk->sequnum = net_ntohs(sequnum); | ||
412 | pk->length = length - sizeof(uint16_t); | 410 | pk->length = length - sizeof(uint16_t); |
413 | memcpy(pk->data, packet + sizeof(uint16_t), length - sizeof(uint16_t)); | 411 | memcpy(pk->data, packet + sizeof(uint16_t), pk->length); |
414 | 412 | ||
415 | if (queue(peer_av->buffer, pk) == -1) { | 413 | if (queue(peer_av->buffer, pk) == -1) { |
416 | free(pk); | 414 | free(pk); |
@@ -503,19 +501,26 @@ int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber | |||
503 | */ | 501 | */ |
504 | static int send_audio_packet(Group_Chats *g_c, uint32_t groupnumber, uint8_t *packet, uint16_t length) | 502 | static int send_audio_packet(Group_Chats *g_c, uint32_t groupnumber, uint8_t *packet, uint16_t length) |
505 | { | 503 | { |
506 | if (!length) { | 504 | if (length == 0 || length > MAX_CRYPTO_DATA_SIZE - 1 - sizeof(uint16_t)) { |
507 | return -1; | 505 | return -1; |
508 | } | 506 | } |
509 | 507 | ||
510 | Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber); | 508 | const uint16_t plen = 1 + sizeof(uint16_t) + length; |
511 | VLA(uint8_t, data, 1 + sizeof(uint16_t) + length); | 509 | |
512 | data[0] = GROUP_AUDIO_PACKET_ID; | 510 | Group_AV *const group_av = (Group_AV *)group_get_object(g_c, groupnumber); |
511 | |||
512 | if (!group_av) { | ||
513 | return -1; | ||
514 | } | ||
515 | |||
516 | uint8_t data[MAX_CRYPTO_DATA_SIZE]; | ||
517 | uint8_t *ptr = data; | ||
518 | *ptr++ = GROUP_AUDIO_PACKET_ID; | ||
513 | 519 | ||
514 | uint16_t sequnum = net_htons(group_av->audio_sequnum); | 520 | ptr += net_pack_u16(ptr, group_av->audio_sequnum); |
515 | memcpy(data + 1, &sequnum, sizeof(sequnum)); | 521 | memcpy(ptr, packet, length); |
516 | memcpy(data + 1 + sizeof(sequnum), packet, length); | ||
517 | 522 | ||
518 | if (send_group_lossy_packet(g_c, groupnumber, data, SIZEOF_VLA(data)) == -1) { | 523 | if (send_group_lossy_packet(g_c, groupnumber, data, plen) == -1) { |
519 | return -1; | 524 | return -1; |
520 | } | 525 | } |
521 | 526 | ||