Skip to content
Permalink
Browse files

Loader: If the module range is bad, don't get stuck trying to scan fo…

…r functions.

Better crash immediately (although that's also not ideal).
  • Loading branch information
hrydgard committed Jan 13, 2020
1 parent ff7bf31 commit c2e857775617e75306bcb98969dd06ee7d0feacb
Showing with 14 additions and 9 deletions.
  1. +14 −9 Core/HLE/sceKernelModule.cpp
@@ -1334,16 +1334,21 @@ static Module *__KernelLoadELFFromPtr(const u8 *ptr, size_t elfSize, u32 loadAdd
if (scan && codeSections.empty()) {
u32 scanStart = module->textStart;
u32 scanEnd = module->textEnd;
// Skip the exports and imports sections, they're not code.
if (scanEnd >= std::min(modinfo->libent, modinfo->libstub)) {
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, std::min(modinfo->libent, modinfo->libstub) - 4, insertSymbols);
scanStart = std::min(modinfo->libentend, modinfo->libstubend);
}
if (scanEnd >= std::max(modinfo->libent, modinfo->libstub)) {
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, std::max(modinfo->libent, modinfo->libstub) - 4, insertSymbols);
scanStart = std::max(modinfo->libentend, modinfo->libstubend);

if (Memory::IsValidRange(scanStart, scanEnd - scanStart)) {
// Skip the exports and imports sections, they're not code.
if (scanEnd >= std::min(modinfo->libent, modinfo->libstub)) {
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, std::min(modinfo->libent, modinfo->libstub) - 4, insertSymbols);
scanStart = std::min(modinfo->libentend, modinfo->libstubend);
}
if (scanEnd >= std::max(modinfo->libent, modinfo->libstub)) {
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, std::max(modinfo->libent, modinfo->libstub) - 4, insertSymbols);
scanStart = std::max(modinfo->libentend, modinfo->libstubend);
}
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, scanEnd, insertSymbols);
} else {
ERROR_LOG(LOADER, "Bad text scan range %08x-%08x", scanStart, scanEnd);
}
insertSymbols = MIPSAnalyst::ScanForFunctions(scanStart, scanEnd, insertSymbols);
}

if (scan) {

0 comments on commit c2e8577

Please sign in to comment.
You can’t perform that action at this time.