From fc8c19989569d55cc7560c86537c7768d1b5a7bb Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 12:59:02 +0700 Subject: [PATCH 1/4] fix soc service - RecvFrom crash on Citra but not on 3DS --- src/core/hle/service/soc_u.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index cfb1af110..1537c385c 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -587,6 +587,8 @@ void SOC_U::RecvFrom(Kernel::HLERequestContext& ctx) { if (ret >= 0 && src_addr_len > 0) { ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + }else { + addr_buff.resize(0); } s32 total_received = ret; From 3b736a72a5b92ab048cd08caa63474ce8c9ce702 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 13:45:28 +0700 Subject: [PATCH 2/4] fix clang-format --- src/core/hle/service/soc_u.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index 1537c385c..df53c5c2a 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -587,7 +587,7 @@ void SOC_U::RecvFrom(Kernel::HLERequestContext& ctx) { if (ret >= 0 && src_addr_len > 0) { ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); - }else { + } else { addr_buff.resize(0); } From e8bb79be2d924e4fa0d74c76b341e08d44944e01 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 20:51:13 +0700 Subject: [PATCH 3/4] do not init and copy to ctr_dest_addr unless have data --- src/core/hle/service/soc_u.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index df53c5c2a..a0177d4fa 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -544,11 +544,10 @@ void SOC_U::SendTo(Kernel::HLERequestContext& ctx) { auto input_buff = rp.PopStaticBuffer(); auto dest_addr_buff = rp.PopStaticBuffer(); - CTRSockAddr ctr_dest_addr; - std::memcpy(&ctr_dest_addr, dest_addr_buff.data(), sizeof(ctr_dest_addr)); - s32 ret = -1; if (addr_len > 0) { + CTRSockAddr ctr_dest_addr; + std::memcpy(&ctr_dest_addr, dest_addr_buff.data(), sizeof(ctr_dest_addr)); sockaddr dest_addr = CTRSockAddr::ToPlatform(ctr_dest_addr); ret = ::sendto(socket_handle, reinterpret_cast(input_buff.data()), len, flags, &dest_addr, sizeof(dest_addr)); From 0e89555a89deaf0d94de3a63e3facd56b7d7a2c7 Mon Sep 17 00:00:00 2001 From: Nguyen Dac Nam Date: Tue, 21 Aug 2018 21:33:19 +0700 Subject: [PATCH 4/4] only get src_adr if input_adr available --- src/core/hle/service/soc_u.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index a0177d4fa..bcbcc4b4c 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -580,13 +580,19 @@ void SOC_U::RecvFrom(Kernel::HLERequestContext& ctx) { std::vector addr_buff(sizeof(ctr_src_addr)); sockaddr src_addr; socklen_t src_addr_len = sizeof(src_addr); - s32 ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, - &src_addr, &src_addr_len); - if (ret >= 0 && src_addr_len > 0) { - ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); - std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + s32 ret = -1; + if (addr_len > 0) { + // Only get src adr if input adr available + ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, + &src_addr, &src_addr_len); + if (ret >= 0 && src_addr_len > 0) { + ctr_src_addr = CTRSockAddr::FromPlatform(src_addr); + std::memcpy(addr_buff.data(), &ctr_src_addr, sizeof(ctr_src_addr)); + } } else { + ret = ::recvfrom(socket_handle, reinterpret_cast(output_buff.data()), len, flags, + NULL, 0); addr_buff.resize(0); }