From 893ef208404e0b30aeb8515f0dc984e2774b00a2 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 2 Jun 2015 13:51:19 +0200 Subject: [PATCH 1/4] Fixed: NULL remotehost in IOCTL_SO_INETATON --- .../Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index d94afd8d10..269f96fd2a 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -921,11 +921,21 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) std::string hostname = Memory::GetString(BufferIn); struct hostent* remoteHost = gethostbyname(hostname.c_str()); - Memory::Write_U32(Common::swap32(*(u32*)remoteHost->h_addr_list[0]), BufferOut); - INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " - "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X",remoteHost->h_addr_list[0] == nullptr ? -1 : 0, - hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, Common::swap32(*(u32*)remoteHost->h_addr_list[0])); - ReturnValue = remoteHost->h_addr_list[0] == nullptr ? 0 : 1; + if (remoteHost == nullptr) + { + INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " + "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: NULL", -1, + hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize); + ReturnValue = 0; + } + else + { + Memory::Write_U32(Common::swap32(*(u32*)remoteHost->h_addr_list[0]), BufferOut); + INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " + "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", remoteHost->h_addr_list[0] == nullptr ? -1 : 0, + hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, Common::swap32(*(u32*)remoteHost->h_addr_list[0])); + ReturnValue = remoteHost->h_addr_list[0] == nullptr ? 0 : 1; + } break; } From 2ff5c451d06b7db512d960590c643aadd3bbff86 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 2 Jun 2015 20:15:05 +0200 Subject: [PATCH 2/4] Cleanup IOCTL_SO_INETATON --- .../Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index 269f96fd2a..fb425d6123 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -921,21 +921,16 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) std::string hostname = Memory::GetString(BufferIn); struct hostent* remoteHost = gethostbyname(hostname.c_str()); - if (remoteHost == nullptr) - { - INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " - "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: NULL", -1, - hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize); - ReturnValue = 0; - } - else - { + if (remoteHost != nullptr) Memory::Write_U32(Common::swap32(*(u32*)remoteHost->h_addr_list[0]), BufferOut); - INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " - "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", remoteHost->h_addr_list[0] == nullptr ? -1 : 0, - hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, Common::swap32(*(u32*)remoteHost->h_addr_list[0])); - ReturnValue = remoteHost->h_addr_list[0] == nullptr ? 0 : 1; - } + + INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " + "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", + (remoteHost == nullptr || remoteHost->h_addr_list[0] == nullptr) ? -1 : 0, + hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, + remoteHost == nullptr ? -1 : Common::swap32(*(u32*)remoteHost->h_addr_list[0])); + + ReturnValue = (remoteHost == nullptr || remoteHost->h_addr_list[0] == nullptr) ? 0 : 1; break; } From b95f18fc0647470a98b1df3929f1a58987ceb700 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 2 Jun 2015 21:09:03 +0200 Subject: [PATCH 3/4] Fix a possible null pointer dereference --- Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index fb425d6123..cecd919c7e 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -921,16 +921,16 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) std::string hostname = Memory::GetString(BufferIn); struct hostent* remoteHost = gethostbyname(hostname.c_str()); - if (remoteHost != nullptr) + if (remoteHost != nullptr && remoteHost->h_addr_list != nullptr) Memory::Write_U32(Common::swap32(*(u32*)remoteHost->h_addr_list[0]), BufferOut); INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", - (remoteHost == nullptr || remoteHost->h_addr_list[0] == nullptr) ? -1 : 0, + (remoteHost == nullptr || remoteHost->h_addr_list == nullptr || remoteHost->h_addr_list[0] == nullptr) ? -1 : 0, hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, - remoteHost == nullptr ? -1 : Common::swap32(*(u32*)remoteHost->h_addr_list[0])); + (remoteHost == nullptr || remoteHost->h_addr_list == nullptr) ? -1 : Common::swap32(*(u32*)remoteHost->h_addr_list[0])); - ReturnValue = (remoteHost == nullptr || remoteHost->h_addr_list[0] == nullptr) ? 0 : 1; + ReturnValue = (remoteHost == nullptr || remoteHost->h_addr_list == nullptr || remoteHost->h_addr_list[0] == nullptr) ? 0 : 1; break; } From f494d1f2245449b1bd8f9bc5fc3b05e62ddbbaf2 Mon Sep 17 00:00:00 2001 From: Sepalani Date: Tue, 2 Jun 2015 22:24:29 +0200 Subject: [PATCH 4/4] Removed: Unnecessary ternaries in IOCTL_SO_INETATON --- .../Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp index cecd919c7e..43eef7776e 100644 --- a/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp +++ b/Source/Core/Core/IPC_HLE/WII_IPC_HLE_Device_net.cpp @@ -921,16 +921,22 @@ IPCCommandResult CWII_IPC_HLE_Device_net_ip_top::IOCtl(u32 _CommandAddress) std::string hostname = Memory::GetString(BufferIn); struct hostent* remoteHost = gethostbyname(hostname.c_str()); - if (remoteHost != nullptr && remoteHost->h_addr_list != nullptr) + if (remoteHost == nullptr || remoteHost->h_addr_list == nullptr || remoteHost->h_addr_list[0] == nullptr) + { + INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = -1 " + "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: None", + hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize); + ReturnValue = 0; + } + else + { Memory::Write_U32(Common::swap32(*(u32*)remoteHost->h_addr_list[0]), BufferOut); - - INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = %d " - "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", - (remoteHost == nullptr || remoteHost->h_addr_list == nullptr || remoteHost->h_addr_list[0] == nullptr) ? -1 : 0, - hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, - (remoteHost == nullptr || remoteHost->h_addr_list == nullptr) ? -1 : Common::swap32(*(u32*)remoteHost->h_addr_list[0])); - - ReturnValue = (remoteHost == nullptr || remoteHost->h_addr_list == nullptr || remoteHost->h_addr_list[0] == nullptr) ? 0 : 1; + INFO_LOG(WII_IPC_NET, "IOCTL_SO_INETATON = 0 " + "%s, BufferIn: (%08x, %i), BufferOut: (%08x, %i), IP Found: %08X", + hostname.c_str(), BufferIn, BufferInSize, BufferOut, BufferOutSize, + Common::swap32(*(u32*)remoteHost->h_addr_list[0])); + ReturnValue = 1; + } break; }