Skip to content

Commit e30266f

Browse files
committed
fix: Fixed uninitialised value copy.
In the "no proxy" case, the `IP_Port` in the default "no proxy" default proxy info is uninitialised. It is never used for any decisions in the code, but it is copied in memory, making it a potential crash on systems with trap representations of ints.
1 parent 30c939e commit e30266f

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

toxcore/TCP_client.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value)
107107
/* return 1 on success
108108
* return 0 on failure
109109
*/
110-
static int connect_sock_to(Socket sock, IP_Port ip_port, TCP_Proxy_Info *proxy_info)
110+
static int connect_sock_to(Socket sock, IP_Port ip_port, const TCP_Proxy_Info *proxy_info)
111111
{
112112
if (proxy_info->proxy_type != TCP_PROXY_NONE) {
113113
ip_port = proxy_info->ip_port;
@@ -663,7 +663,7 @@ void onion_response_handler(TCP_Client_Connection *con, tcp_onion_response_cb *o
663663
/* Create new TCP connection to ip_port/public_key
664664
*/
665665
TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip_port, const uint8_t *public_key,
666-
const uint8_t *self_public_key, const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info)
666+
const uint8_t *self_public_key, const uint8_t *self_secret_key, const TCP_Proxy_Info *proxy_info)
667667
{
668668
if (networking_at_startup() != 0) {
669669
return nullptr;
@@ -673,10 +673,9 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip
673673
return nullptr;
674674
}
675675

676-
TCP_Proxy_Info default_proxyinfo;
676+
const TCP_Proxy_Info default_proxyinfo = {{{{0}}}, TCP_PROXY_NONE};
677677

678678
if (proxy_info == nullptr) {
679-
default_proxyinfo.proxy_type = TCP_PROXY_NONE;
680679
proxy_info = &default_proxyinfo;
681680
}
682681

toxcore/TCP_client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value);
5050
/* Create new TCP connection to ip_port/public_key
5151
*/
5252
TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip_port, const uint8_t *public_key,
53-
const uint8_t *self_public_key, const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info);
53+
const uint8_t *self_public_key, const uint8_t *self_secret_key, const TCP_Proxy_Info *proxy_info);
5454

5555
/* Run the TCP connection
5656
*/

0 commit comments

Comments
 (0)