Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions core/hw/naomi/naomi_m3comm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ void NaomiM3Comm::connectNetwork()
bool NaomiM3Comm::receiveNetwork()
{
const u32 slot_size = swap16(*(u16*)&m68k_ram[0x204]);
const u32 packet_size = slot_size * slot_count;
const u64 packet_size64 = (u64)slot_size * slot_count;
if (slot_size == 0 || slot_count < 2 || packet_size64 >= 0x4000
|| 0x100 + slot_size + packet_size64 > sizeof(comm_ram))
throw NaomiNetwork::Exception("Invalid communication RAM layout");
const u32 packet_size = (u32)packet_size64;

std::unique_ptr<u8[]> buf = std::make_unique<u8[]>(packet_size);

Expand All @@ -113,7 +117,12 @@ bool NaomiM3Comm::receiveNetwork()

void NaomiM3Comm::sendNetwork()
{
const u32 packet_size = swap16(*(u16*)&m68k_ram[0x204]) * slot_count;
const u32 slot_size = swap16(*(u16*)&m68k_ram[0x204]);
const u64 packet_size64 = (u64)slot_size * slot_count;
if (slot_size == 0 || slot_count < 2 || packet_size64 >= 0x4000
|| 0x100 + packet_size64 > sizeof(comm_ram))
throw NaomiNetwork::Exception("Invalid communication RAM layout");
const u32 packet_size = (u32)packet_size64;
naomiNetwork.send(&comm_ram[0x100], packet_size, packet_number);
packet_number++;
}
Expand Down
13 changes: 12 additions & 1 deletion core/network/naomi_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ bool NaomiNetwork::receive(const sockaddr_in *addr, const Packet *packet, u32 si
}
if (slave == nullptr)
{
if (maxSlots <= 1 || slaves.size() >= (unsigned)maxSlots - 1)
break;
slaves.push_back(Slave());
slave = &slaves.back();
slave->state = 0; // unused
Expand Down Expand Up @@ -246,6 +248,9 @@ bool NaomiNetwork::receive(const sockaddr_in *addr, const Packet *packet, u32 si
case SyncReply:
if (!config::ActAsServer && !_startNow)
{
if (packet->sync.nodeId == 0 || packet->sync.nodeId >= maxSlots
|| (serverIp != INADDR_BROADCAST && addr->sin_addr.s_addr != serverIp))
break;
serverIp = addr->sin_addr.s_addr;
slotId = packet->sync.nodeId;
nextPeer.sin_family = AF_INET;
Expand All @@ -257,7 +262,11 @@ bool NaomiNetwork::receive(const sockaddr_in *addr, const Packet *packet, u32 si
break;

case Start:
if (!_startNow)
if (!config::ActAsServer && !_startNow
&& addr->sin_addr.s_addr == serverIp
&& packet->start.nodeCount >= 2
&& packet->start.nodeCount <= maxSlots
&& slotId < packet->start.nodeCount)
{
slotCount = packet->start.nodeCount;
sendAck(addr);
Expand All @@ -266,6 +275,8 @@ bool NaomiNetwork::receive(const sockaddr_in *addr, const Packet *packet, u32 si
break;

case Data:
if (!_startNow)
break;
if (!receivedData.empty())
INFO_LOG(NETWORK, "Received packet overwritten");
receivedData.resize(size - packet->size(0));
Expand Down
Loading