diff --git a/lib/src/remote/holepunch.c b/lib/src/remote/holepunch.c index 44bb4518..90c50728 100644 --- a/lib/src/remote/holepunch.c +++ b/lib/src/remote/holepunch.c @@ -944,6 +944,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_holepunch_session_start( return CHIAKI_ERR_UNKNOWN; } chiaki_mutex_unlock(&session->state_mutex); + ChiakiErrorCode err_stun = get_stun_servers(session); + if(err_stun != CHIAKI_ERR_SUCCESS) + { + CHIAKI_LOGW(session->log, "Getting stun servers returned error %s", chiaki_error_string(err_stun)); + } ChiakiErrorCode err; session->console_type = console_type; if(console_type == CHIAKI_HOLEPUNCH_CONSOLE_TYPE_PS4) @@ -3378,11 +3383,6 @@ static bool get_client_addr_remote_stun(Session *session, char *address, uint16_ // run STUN test if it hasn't been run yet if(session->stun_allocation_increment == -1) { - ChiakiErrorCode err = get_stun_servers(session); - if(err != CHIAKI_ERR_SUCCESS) - { - CHIAKI_LOGW(session->log, "Getting stun servers returned error %s", chiaki_error_string(err)); - } if (!stun_port_allocation_test(session->log, address, port, &session->stun_allocation_increment, &session->stun_random_allocation, session->stun_server_list, session->num_stun_servers, sock)) { CHIAKI_LOGE(session->log, "get_client_addr_remote_stun: Failed to get external address"); diff --git a/lib/src/remote/stun.h b/lib/src/remote/stun.h index aa325f73..77631a9c 100644 --- a/lib/src/remote/stun.h +++ b/lib/src/remote/stun.h @@ -548,7 +548,7 @@ static bool stun_get_external_address_from_server(ChiakiLog *log, StunServer *se // Verify length stored in binding_resp[2] is correct size_t expected_size = ntohs(*(uint16_t*)(&binding_resp[2])) + STUN_HEADER_SIZE; - if (received != ntohs(*(uint16_t*)(&binding_resp[2])) + STUN_HEADER_SIZE) { + if (received != expected_size) { CHIAKI_LOGE(log, "remote/stun.h: Received STUN response with invalid length: %zd received, %zu expected", received, expected_size); return false; } @@ -566,12 +566,12 @@ static bool stun_get_external_address_from_server(ChiakiLog *log, StunServer *se //uint16_t response_attrs_length = ntohs(*(uint16_t*)(&binding_resp[2])); uint16_t response_pos = STUN_HEADER_SIZE; // Check we can read 4 bytes of attribute data - while (response_pos < (received - 4)) + while (response_pos < (received - 3)) { uint16_t attr_type = ntohs(*(uint16_t*)(&binding_resp[response_pos])); uint16_t attr_length = ntohs(*(uint16_t*)(&binding_resp[response_pos + 2])); // check that the whole advertised message has been received - if(response_pos >= (received - (sizeof(attr_type) + sizeof(attr_length) + attr_length))) + if(response_pos > (received - (sizeof(attr_type) + sizeof(attr_length) + attr_length))) { CHIAKI_LOGE(log, "remote/stun.h: Received STUN response with invalid data"); return false;