diff options
Diffstat (limited to 'protocols/Tox/libtox/src')
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/network.c | 23 | ||||
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/network.h | 4 | ||||
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/onion.c | 24 | ||||
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/tox.api.h | 2 | ||||
-rw-r--r-- | protocols/Tox/libtox/src/toxcore/tox.h | 2 |
5 files changed, 43 insertions, 12 deletions
diff --git a/protocols/Tox/libtox/src/toxcore/network.c b/protocols/Tox/libtox/src/toxcore/network.c index 6e19a58610..984071d4e3 100644 --- a/protocols/Tox/libtox/src/toxcore/network.c +++ b/protocols/Tox/libtox/src/toxcore/network.c @@ -377,7 +377,7 @@ static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, if (res < 0) { /* Windows doesn't necessarily know %zu */ int error = net_error(); - char *strerror = net_new_strerror(error); + const char *strerror = net_new_strerror(error); LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x", buffer[0], message, (buflen < 999 ? buflen : 999), 'E', ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), error, @@ -504,7 +504,7 @@ static int receivepacket(Logger *log, Socket sock, IP_Port *ip_port, uint8_t *da int error = net_error(); if (fail_or_len < 0 && error != TOX_EWOULDBLOCK) { - char *strerror = net_new_strerror(error); + const char *strerror = net_new_strerror(error); LOGGER_ERROR(log, "Unexpected error reading from socket: %u, %s", error, strerror); net_kill_strerror(strerror); } @@ -688,7 +688,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 /* Check for socket error. */ if (!sock_valid(temp->sock)) { int neterror = net_error(); - char *strerror = net_new_strerror(neterror); + const char *strerror = net_new_strerror(neterror); LOGGER_ERROR(log, "Failed to get a socket?! %d, %s", neterror, strerror); net_kill_strerror(strerror); free(temp); @@ -779,7 +779,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 int res = setsockopt(temp->sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, (const char *)&mreq, sizeof(mreq)); int neterror = net_error(); - char *strerror = net_new_strerror(neterror); + const char *strerror = net_new_strerror(neterror); LOGGER_DEBUG(log, res < 0 ? "Failed to activate local multicast membership. (%d, %s)" : "Local multicast group FF02::1 joined successfully", neterror, strerror); net_kill_strerror(strerror); @@ -840,7 +840,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1 char ip_str[IP_NTOA_LEN]; int neterror = net_error(); - char *strerror = net_new_strerror(neterror); + const char *strerror = net_new_strerror(neterror); LOGGER_ERROR(log, "Failed to bind socket: %d, %s IP: %s port_from: %u port_to: %u", neterror, strerror, ip_ntoa(&ip, ip_str, sizeof(ip_str)), port_from, port_to); net_kill_strerror(strerror); @@ -1544,10 +1544,17 @@ int net_error(void) #endif } -char *net_new_strerror(int error) +const char *net_new_strerror(int error) { #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) char *str = nullptr; + // Windows API is weird. The 5th function arg is of char* type, but we + // have to pass char** so that it could assign new memory block to our + // pointer, so we have to cast our char** to char* for the compilation + // not to fail (otherwise it would fail to find a variant of this function + // accepting char** as the 5th arg) and Windows inside casts it back + // to char** to do the assignment. So no, this cast you see here, although + // it looks weird, is not a mistake. FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error, 0, (char *)&str, 0, nullptr); return str; @@ -1556,9 +1563,9 @@ char *net_new_strerror(int error) #endif } -void net_kill_strerror(char *strerror) +void net_kill_strerror(const char *strerror) { #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - LocalFree(strerror); + LocalFree((char *)strerror); #endif } diff --git a/protocols/Tox/libtox/src/toxcore/network.h b/protocols/Tox/libtox/src/toxcore/network.h index 193a02faf8..10ddef0217 100644 --- a/protocols/Tox/libtox/src/toxcore/network.h +++ b/protocols/Tox/libtox/src/toxcore/network.h @@ -424,13 +424,13 @@ int net_error(void); * return pointer to a NULL-terminated string describing the error code on * success. The returned string must be freed using net_kill_strerror(). */ -char *net_new_strerror(int error); +const char *net_new_strerror(int error); /* Frees the string returned by net_new_strerror(). * It's valid to pass NULL as the argument, the function does nothing in this * case. */ -void net_kill_strerror(char *strerror); +void net_kill_strerror(const char *strerror); /* Initialize networking. * bind to ip and port. diff --git a/protocols/Tox/libtox/src/toxcore/onion.c b/protocols/Tox/libtox/src/toxcore/onion.c index 48cc4d768c..740c25ce10 100644 --- a/protocols/Tox/libtox/src/toxcore/onion.c +++ b/protocols/Tox/libtox/src/toxcore/onion.c @@ -471,6 +471,15 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui return 1; } + if (len <= SIZE_IPPORT) { + return 1; + } + + if (plain[SIZE_IPPORT] != NET_PACKET_ANNOUNCE_REQUEST && + plain[SIZE_IPPORT] != NET_PACKET_ONION_DATA_REQUEST) { + return 1; + } + IP_Port send_to; if (ipport_unpack(&send_to, plain, len, 0) == -1) { @@ -514,6 +523,11 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui return 1; } + if (packet[1 + RETURN_3] != NET_PACKET_ANNOUNCE_RESPONSE && + packet[1 + RETURN_3] != NET_PACKET_ONION_DATA_RESPONSE) { + return 1; + } + change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT + RETURN_2]; @@ -555,6 +569,11 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui return 1; } + if (packet[1 + RETURN_2] != NET_PACKET_ANNOUNCE_RESPONSE && + packet[1 + RETURN_2] != NET_PACKET_ONION_DATA_RESPONSE) { + return 1; + } + change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT + RETURN_1]; @@ -596,6 +615,11 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui return 1; } + if (packet[1 + RETURN_1] != NET_PACKET_ANNOUNCE_RESPONSE && + packet[1 + RETURN_1] != NET_PACKET_ONION_DATA_RESPONSE) { + return 1; + } + change_symmetric_key(onion); uint8_t plain[SIZE_IPPORT]; diff --git a/protocols/Tox/libtox/src/toxcore/tox.api.h b/protocols/Tox/libtox/src/toxcore/tox.api.h index d6148414be..1c3b112115 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.api.h +++ b/protocols/Tox/libtox/src/toxcore/tox.api.h @@ -179,7 +179,7 @@ const VERSION_MINOR = 2; * The patch or revision number. Incremented when bugfixes are applied without * changing any functionality or API or ABI. */ -const VERSION_PATCH = 1; +const VERSION_PATCH = 2; /** * A macro to check at preprocessing time whether the client code is compatible diff --git a/protocols/Tox/libtox/src/toxcore/tox.h b/protocols/Tox/libtox/src/toxcore/tox.h index c65f1e2566..d58340950d 100644 --- a/protocols/Tox/libtox/src/toxcore/tox.h +++ b/protocols/Tox/libtox/src/toxcore/tox.h @@ -180,7 +180,7 @@ uint32_t tox_version_minor(void); * The patch or revision number. Incremented when bugfixes are applied without * changing any functionality or API or ABI. */ -#define TOX_VERSION_PATCH 1 +#define TOX_VERSION_PATCH 2 uint32_t tox_version_patch(void); |