diff options
Diffstat (limited to 'toxcore/TCP_client.c')
-rw-r--r-- | toxcore/TCP_client.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index 3d65415e..0910534d 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c | |||
@@ -120,7 +120,7 @@ static int proxy_http_read_connection_response(TCP_Client_Connection *TCP_conn) | |||
120 | unsigned int data_left = TCP_socket_data_recv_buffer(TCP_conn->sock); | 120 | unsigned int data_left = TCP_socket_data_recv_buffer(TCP_conn->sock); |
121 | 121 | ||
122 | if (data_left) { | 122 | if (data_left) { |
123 | uint8_t temp_data[data_left]; | 123 | VLA(uint8_t, temp_data, data_left); |
124 | read_TCP_packet(TCP_conn->sock, temp_data, data_left); | 124 | read_TCP_packet(TCP_conn->sock, temp_data, data_left); |
125 | } | 125 | } |
126 | 126 | ||
@@ -387,18 +387,18 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const | |||
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | uint8_t packet[sizeof(uint16_t) + length + CRYPTO_MAC_SIZE]; | 390 | VLA(uint8_t, packet, sizeof(uint16_t) + length + CRYPTO_MAC_SIZE); |
391 | 391 | ||
392 | uint16_t c_length = htons(length + CRYPTO_MAC_SIZE); | 392 | uint16_t c_length = htons(length + CRYPTO_MAC_SIZE); |
393 | memcpy(packet, &c_length, sizeof(uint16_t)); | 393 | memcpy(packet, &c_length, sizeof(uint16_t)); |
394 | int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); | 394 | int len = encrypt_data_symmetric(con->shared_key, con->sent_nonce, data, length, packet + sizeof(uint16_t)); |
395 | 395 | ||
396 | if ((unsigned int)len != (sizeof(packet) - sizeof(uint16_t))) { | 396 | if ((unsigned int)len != (SIZEOF_VLA(packet) - sizeof(uint16_t))) { |
397 | return -1; | 397 | return -1; |
398 | } | 398 | } |
399 | 399 | ||
400 | if (priority) { | 400 | if (priority) { |
401 | len = sendpriority ? send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL) : 0; | 401 | len = sendpriority ? send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL) : 0; |
402 | 402 | ||
403 | if (len <= 0) { | 403 | if (len <= 0) { |
404 | len = 0; | 404 | len = 0; |
@@ -406,14 +406,14 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const | |||
406 | 406 | ||
407 | increment_nonce(con->sent_nonce); | 407 | increment_nonce(con->sent_nonce); |
408 | 408 | ||
409 | if ((unsigned int)len == sizeof(packet)) { | 409 | if ((unsigned int)len == SIZEOF_VLA(packet)) { |
410 | return 1; | 410 | return 1; |
411 | } | 411 | } |
412 | 412 | ||
413 | return add_priority(con, packet, sizeof(packet), len); | 413 | return add_priority(con, packet, SIZEOF_VLA(packet), len); |
414 | } | 414 | } |
415 | 415 | ||
416 | len = send(con->sock, (const char *)packet, sizeof(packet), MSG_NOSIGNAL); | 416 | len = send(con->sock, (const char *)packet, SIZEOF_VLA(packet), MSG_NOSIGNAL); |
417 | 417 | ||
418 | if (len <= 0) { | 418 | if (len <= 0) { |
419 | return 0; | 419 | return 0; |
@@ -421,12 +421,12 @@ static int write_packet_TCP_secure_connection(TCP_Client_Connection *con, const | |||
421 | 421 | ||
422 | increment_nonce(con->sent_nonce); | 422 | increment_nonce(con->sent_nonce); |
423 | 423 | ||
424 | if ((unsigned int)len == sizeof(packet)) { | 424 | if ((unsigned int)len == SIZEOF_VLA(packet)) { |
425 | return 1; | 425 | return 1; |
426 | } | 426 | } |
427 | 427 | ||
428 | memcpy(con->last_packet, packet, sizeof(packet)); | 428 | memcpy(con->last_packet, packet, SIZEOF_VLA(packet)); |
429 | con->last_packet_length = sizeof(packet); | 429 | con->last_packet_length = SIZEOF_VLA(packet); |
430 | con->last_packet_sent = len; | 430 | con->last_packet_sent = len; |
431 | return 1; | 431 | return 1; |
432 | } | 432 | } |
@@ -478,10 +478,10 @@ int send_data(TCP_Client_Connection *con, uint8_t con_id, const uint8_t *data, u | |||
478 | return 0; | 478 | return 0; |
479 | } | 479 | } |
480 | 480 | ||
481 | uint8_t packet[1 + length]; | 481 | VLA(uint8_t, packet, 1 + length); |
482 | packet[0] = con_id + NUM_RESERVED_PORTS; | 482 | packet[0] = con_id + NUM_RESERVED_PORTS; |
483 | memcpy(packet + 1, data, length); | 483 | memcpy(packet + 1, data, length); |
484 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet), 0); | 484 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
485 | } | 485 | } |
486 | 486 | ||
487 | /* return 1 on success. | 487 | /* return 1 on success. |
@@ -494,11 +494,11 @@ int send_oob_packet(TCP_Client_Connection *con, const uint8_t *public_key, const | |||
494 | return -1; | 494 | return -1; |
495 | } | 495 | } |
496 | 496 | ||
497 | uint8_t packet[1 + CRYPTO_PUBLIC_KEY_SIZE + length]; | 497 | VLA(uint8_t, packet, 1 + CRYPTO_PUBLIC_KEY_SIZE + length); |
498 | packet[0] = TCP_PACKET_OOB_SEND; | 498 | packet[0] = TCP_PACKET_OOB_SEND; |
499 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); | 499 | memcpy(packet + 1, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
500 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length); | 500 | memcpy(packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, data, length); |
501 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet), 0); | 501 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
502 | } | 502 | } |
503 | 503 | ||
504 | 504 | ||
@@ -614,10 +614,10 @@ int send_disconnect_request(TCP_Client_Connection *con, uint8_t con_id) | |||
614 | */ | 614 | */ |
615 | int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length) | 615 | int send_onion_request(TCP_Client_Connection *con, const uint8_t *data, uint16_t length) |
616 | { | 616 | { |
617 | uint8_t packet[1 + length]; | 617 | VLA(uint8_t, packet, 1 + length); |
618 | packet[0] = TCP_PACKET_ONION_REQUEST; | 618 | packet[0] = TCP_PACKET_ONION_REQUEST; |
619 | memcpy(packet + 1, data, length); | 619 | memcpy(packet + 1, data, length); |
620 | return write_packet_TCP_secure_connection(con, packet, sizeof(packet), 0); | 620 | return write_packet_TCP_secure_connection(con, packet, SIZEOF_VLA(packet), 0); |
621 | } | 621 | } |
622 | 622 | ||
623 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, | 623 | void onion_response_handler(TCP_Client_Connection *con, int (*onion_callback)(void *object, const uint8_t *data, |