mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-06-05 17:03:45 -04:00
[hid_core] fix: bounds-check aruid index in GetControllerFromNpadIdType
GetIndexFromAruid returns AruidIndexMax as the "not found" value, but both GetControllerFromNpadIdType overloads were using that value to index controller_data without checking it first. When a game routes through DisconnectNpad before its applet resource is registered, we can end up indexing past the end of controller_data. That seems to be what was crashing some games on launch, especially on macOS and Android, where the out-of-bounds read is less likely to just slide by unnoticed. So yeah, AruidIndexMax is a sentinel, not a real controller_data index, so we should not treat it like one. Fixes: https://github.com/eden-emulator/Issue-Reports/issues/438 Fixes: https://github.com/eden-emulator/Issue-Reports/issues/439
This commit is contained in:
parent
ff7bbaea7d
commit
7a33c1f95f
1 changed files with 10 additions and 2 deletions
|
|
@ -1144,7 +1144,11 @@ NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(u64 aruid,
|
||||||
npad_id = Core::HID::NpadIdType::Player1;
|
npad_id = Core::HID::NpadIdType::Player1;
|
||||||
}
|
}
|
||||||
const auto npad_index = NpadIdTypeToIndex(npad_id);
|
const auto npad_index = NpadIdTypeToIndex(npad_id);
|
||||||
const auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
|
auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
|
||||||
|
if (aruid_index >= AruidIndexMax) {
|
||||||
|
LOG_ERROR(Service_HID, "Invalid aruid:{:016X}", aruid);
|
||||||
|
aruid_index = 0;
|
||||||
|
}
|
||||||
return controller_data[aruid_index][npad_index];
|
return controller_data[aruid_index][npad_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1155,7 +1159,11 @@ const NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(
|
||||||
npad_id = Core::HID::NpadIdType::Player1;
|
npad_id = Core::HID::NpadIdType::Player1;
|
||||||
}
|
}
|
||||||
const auto npad_index = NpadIdTypeToIndex(npad_id);
|
const auto npad_index = NpadIdTypeToIndex(npad_id);
|
||||||
const auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
|
auto aruid_index = applet_resource_holder.applet_resource->GetIndexFromAruid(aruid);
|
||||||
|
if (aruid_index >= AruidIndexMax) {
|
||||||
|
LOG_ERROR(Service_HID, "Invalid aruid:{:016X}", aruid);
|
||||||
|
aruid_index = 0;
|
||||||
|
}
|
||||||
return controller_data[aruid_index][npad_index];
|
return controller_data[aruid_index][npad_index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue