mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-10 03:18:55 +02:00
[hle/sockets] fix crash when socket() isn't initialized but send()/recv() are called
Signed-off-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
5322bce4b8
commit
ea1715a25f
1 changed files with 58 additions and 0 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
|
||||||
|
#include "common/logging.h"
|
||||||
#include "common/socket_types.h"
|
#include "common/socket_types.h"
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/kernel/k_thread.h"
|
#include "core/hle/kernel/k_thread.h"
|
||||||
|
|
@ -629,6 +630,12 @@ Errno BSD::BindImpl(s32 fd, std::span<const u8> addr) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
ASSERT(addr.size() == sizeof(SockAddrIn));
|
ASSERT(addr.size() == sizeof(SockAddrIn));
|
||||||
auto addr_in = GetValue<SockAddrIn>(addr);
|
auto addr_in = GetValue<SockAddrIn>(addr);
|
||||||
|
|
||||||
|
|
@ -640,6 +647,11 @@ Errno BSD::ConnectImpl(s32 fd, std::span<const u8> addr) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
UNIMPLEMENTED_IF(addr.size() != sizeof(SockAddrIn));
|
UNIMPLEMENTED_IF(addr.size() != sizeof(SockAddrIn));
|
||||||
auto addr_in = GetValue<SockAddrIn>(addr);
|
auto addr_in = GetValue<SockAddrIn>(addr);
|
||||||
|
|
||||||
|
|
@ -658,6 +670,11 @@ Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetPeerName();
|
const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetPeerName();
|
||||||
if (bsd_errno != Network::Errno::SUCCESS) {
|
if (bsd_errno != Network::Errno::SUCCESS) {
|
||||||
return Translate(bsd_errno);
|
return Translate(bsd_errno);
|
||||||
|
|
@ -675,6 +692,11 @@ Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetSockName();
|
const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetSockName();
|
||||||
if (bsd_errno != Network::Errno::SUCCESS) {
|
if (bsd_errno != Network::Errno::SUCCESS) {
|
||||||
return Translate(bsd_errno);
|
return Translate(bsd_errno);
|
||||||
|
|
@ -691,6 +713,10 @@ Errno BSD::ListenImpl(s32 fd, s32 backlog) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
return Translate(file_descriptors[fd]->socket->Listen(backlog));
|
return Translate(file_descriptors[fd]->socket->Listen(backlog));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -698,6 +724,10 @@ std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return {-1, Errno::BADF};
|
return {-1, Errno::BADF};
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return {-1, Errno::BADF};
|
||||||
|
}
|
||||||
|
|
||||||
FileDescriptor& descriptor = *file_descriptors[fd];
|
FileDescriptor& descriptor = *file_descriptors[fd];
|
||||||
|
|
||||||
|
|
@ -724,6 +754,10 @@ Errno BSD::GetSockOptImpl(s32 fd, u32 level, OptName optname, std::vector<u8>& o
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
if (level != static_cast<u32>(SocketLevel::SOCKET)) {
|
if (level != static_cast<u32>(SocketLevel::SOCKET)) {
|
||||||
UNIMPLEMENTED_MSG("Unknown getsockopt level");
|
UNIMPLEMENTED_MSG("Unknown getsockopt level");
|
||||||
|
|
@ -755,6 +789,10 @@ Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, std::span<const u8
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
if (level != static_cast<u32>(SocketLevel::SOCKET)) {
|
if (level != static_cast<u32>(SocketLevel::SOCKET)) {
|
||||||
LOG_WARNING(Service, "(STUBBED) setsockopt with level={}, optname={}", level, optname);
|
LOG_WARNING(Service, "(STUBBED) setsockopt with level={}, optname={}", level, optname);
|
||||||
|
|
@ -805,6 +843,10 @@ Errno BSD::ShutdownImpl(s32 fd, s32 how) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how));
|
const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how));
|
||||||
return Translate(file_descriptors[fd]->socket->Shutdown(host_how));
|
return Translate(file_descriptors[fd]->socket->Shutdown(host_how));
|
||||||
}
|
}
|
||||||
|
|
@ -887,6 +929,10 @@ std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, std::span<const u8> messa
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return {-1, Errno::BADF};
|
return {-1, Errno::BADF};
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return {-1, Errno::BADF};
|
||||||
|
}
|
||||||
return Translate(file_descriptors[fd]->socket->Send(message, flags));
|
return Translate(file_descriptors[fd]->socket->Send(message, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -895,6 +941,10 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, std::span<const u8> mes
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return {-1, Errno::BADF};
|
return {-1, Errno::BADF};
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return {-1, Errno::BADF};
|
||||||
|
}
|
||||||
|
|
||||||
Network::SockAddrIn addr_in;
|
Network::SockAddrIn addr_in;
|
||||||
Network::SockAddrIn* p_addr_in = nullptr;
|
Network::SockAddrIn* p_addr_in = nullptr;
|
||||||
|
|
@ -912,6 +962,10 @@ Errno BSD::CloseImpl(s32 fd) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return Errno::BADF;
|
return Errno::BADF;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return Errno::BADF;
|
||||||
|
}
|
||||||
|
|
||||||
const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close());
|
const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close());
|
||||||
if (bsd_errno != Errno::SUCCESS) {
|
if (bsd_errno != Errno::SUCCESS) {
|
||||||
|
|
@ -947,6 +1001,10 @@ std::optional<std::shared_ptr<Network::SocketBase>> BSD::GetSocket(s32 fd) {
|
||||||
if (!IsFileDescriptorValid(fd)) {
|
if (!IsFileDescriptorValid(fd)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
if (!file_descriptors[fd]->socket) {
|
||||||
|
LOG_WARNING(Service, "Uninitialized socket");
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
return file_descriptors[fd]->socket;
|
return file_descriptors[fd]->socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue