Skip to content

Commit

Permalink
Merge pull request #35 from MikeIsAStar/ensure-that-invalid-items-can…
Browse files Browse the repository at this point in the history
…-not-be-dropped

[MKW] Ensure that invalid items can not be trailed nor dropped
  • Loading branch information
mkwcat authored Jan 19, 2024
2 parents 507b86b + e86f55d commit 2e38d9d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
26 changes: 26 additions & 0 deletions payload/import/mkwItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ static bool CanTrailItem(ItemBox item)
return !itemBehaviourTable[itemToTrail].useFunction;
}

static bool CanTrailItemObject(ItemObject itemObject)
{
switch (itemObject) {
case ItemObject::GreenShell... ItemObject::Banana:
case ItemObject::FakeItemBox:
case ItemObject::Bob_omb: {
return true;
}
default: {
return false;
}
}
}

static bool CanDropItemObject(ItemObject itemObject)
{
switch (itemObject) {
case ItemObject::GreenShell... ItemObject::BulletBill: {
return true;
}
default: {
return false;
}
}
}

static bool IsHeldItemValidVS(ItemBox item)
{
switch (item) {
Expand Down
19 changes: 19 additions & 0 deletions payload/import/mkwNet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ class EVENTHandler
NoEvent = 0,
ItemUsed = 1,
ItemThrown = 2,
ItemHitTrailed = 3,
ItemDropped = 7,
};

bool isItemObjectValid() const
Expand Down Expand Up @@ -261,6 +263,12 @@ class EVENTHandler
case EventType::ItemThrown: {
return CanThrowItem(ItemObjectToItemBox(item));
}
case EventType::ItemHitTrailed: {
return CanTrailItemObject(item);
}
case EventType::ItemDropped: {
return CanDropItemObject(item);
}
default: {
return true;
}
Expand All @@ -278,6 +286,17 @@ class EVENTHandler

static_assert(sizeof(EventInfo) == 0x01);

bool containsInvalidItemObject() const
{
for (size_t n = 0; n < sizeof(eventInfo); n++) {
if (!eventInfo[n].isItemObjectValid()) {
return true;
}
}

return false;
}

bool isValid(u8 packetSize) const
{
u32 expectedPacketSize = sizeof(eventInfo);
Expand Down
10 changes: 10 additions & 0 deletions payload/wwfcSecurity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ static bool IsEVENTPacketDataValid(
const EVENTHandler::Packet* eventPacket =
reinterpret_cast<const EVENTHandler::Packet*>(packet);

// Always ensure that the packet does not contain any invalid item objects,
// as this can cause a buffer overflow to occur.
if (eventPacket->containsInvalidItemObject()) {
return false;
}

if (!RKNetController::Instance()->inVanillaMatch()) {
return true;
}

if (!eventPacket->isValid(packetSize)) {
return false;
}
Expand Down

0 comments on commit 2e38d9d

Please sign in to comment.