From 2cdda8c564eba94f0291160567aba7204f855242 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Tue, 3 Mar 2020 19:52:06 -0700 Subject: [PATCH 1/3] input/udp - Dont log on invalid packet received --- src/input_common/udp/protocol.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/input_common/udp/protocol.cpp b/src/input_common/udp/protocol.cpp index a982ac49d..5e50bd612 100644 --- a/src/input_common/udp/protocol.cpp +++ b/src/input_common/udp/protocol.cpp @@ -31,7 +31,6 @@ namespace Response { */ std::optional Validate(u8* data, std::size_t size) { if (size < sizeof(Header)) { - LOG_DEBUG(Input, "Invalid UDP packet received"); return std::nullopt; } Header header{}; From fc205a1bc54543603f49ee3e42a51e7b79f6441d Mon Sep 17 00:00:00 2001 From: James Rowe Date: Tue, 3 Mar 2020 20:05:42 -0700 Subject: [PATCH 2/3] Frontend/SDL - Provide proper default for UDP input When the default file is read in, the settings default value is only used when the key is missing. As it was, the key existed, but the value was empty string causing it to accept that as a value to pass into the core --- src/yuzu_cmd/default_ini.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index df7473858..085ffbc81 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -84,7 +84,7 @@ touch_device= # from any cemuhook compatible motion program. # IPv4 address of the udp input server (Default "127.0.0.1") -udp_input_address= +udp_input_address=127.0.0.1 # Port of the udp input server. (Default 26760) udp_input_port= From 002d9508a04f9cc7de870a3144c798a84fadca77 Mon Sep 17 00:00:00 2001 From: James Rowe Date: Tue, 3 Mar 2020 23:46:05 -0700 Subject: [PATCH 3/3] input/udp - Add minor error handling to prevent bad input from crashing --- src/input_common/udp/client.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index 2228571a6..e82ae7ef1 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -32,8 +32,16 @@ public: SocketCallback callback) : callback(std::move(callback)), timer(io_service), socket(io_service, udp::endpoint(udp::v4(), 0)), client_id(client_id), - pad_index(pad_index), - send_endpoint(udp::endpoint(boost::asio::ip::make_address_v4(host), port)) {} + pad_index(pad_index) { + boost::system::error_code ec{}; + auto ipv4 = boost::asio::ip::make_address_v4(host, ec); + if (ec.failed()) { + LOG_ERROR(Input, "Invalid IPv4 address \"{}\" provided to socket", host); + ipv4 = boost::asio::ip::address_v4{}; + } + + send_endpoint = {udp::endpoint(ipv4, port)}; + } void Stop() { io_service.stop(); @@ -85,17 +93,18 @@ private: } void HandleSend(const boost::system::error_code& error) { + boost::system::error_code _ignored{}; // Send a request for getting port info for the pad Request::PortInfo port_info{1, {pad_index, 0, 0, 0}}; const auto port_message = Request::Create(port_info, client_id); std::memcpy(&send_buffer1, &port_message, PORT_INFO_SIZE); - socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint); + socket.send_to(boost::asio::buffer(send_buffer1), send_endpoint, {}, _ignored); // Send a request for getting pad data for the pad Request::PadData pad_data{Request::PadData::Flags::Id, pad_index, EMPTY_MAC_ADDRESS}; const auto pad_message = Request::Create(pad_data, client_id); std::memcpy(send_buffer2.data(), &pad_message, PAD_DATA_SIZE); - socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint); + socket.send_to(boost::asio::buffer(send_buffer2), send_endpoint, {}, _ignored); StartSend(timer.expiry()); }