From 18f1ea54532581205a752827d31528dbb6c27386 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sat, 16 Dec 2023 22:11:14 +0200 Subject: [PATCH] [APT] Gracefully handle SetApplicationCpuTimeLimit with invalid inputs --- src/core/services/apt.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/services/apt.cpp b/src/core/services/apt.cpp index 754baa139..9d02bf94d 100644 --- a/src/core/services/apt.cpp +++ b/src/core/services/apt.cpp @@ -2,6 +2,7 @@ #include "ipc.hpp" #include "kernel.hpp" +#include #include namespace APTCommands { @@ -311,12 +312,14 @@ void APTService::setApplicationCpuTimeLimit(u32 messagePointer) { log("APT::SetApplicationCpuTimeLimit (percentage = %d%%)\n", percentage); if (percentage < 5 || percentage > 89 || fixed != 1) { - Helpers::panic("Invalid parameters passed to APT::SetApplicationCpuTimeLimit"); - } else { - mem.write32(messagePointer, IPC::responseHeader(0x4F, 1, 0)); - mem.write32(messagePointer + 4, Result::Success); - cpuTimeLimit = percentage; + Helpers::warn("Invalid parameter passed to APT::SetApplicationCpuTimeLimit: (percentage, fixed) = (%d, %d)\n", percentage, fixed); + // TODO: Does the clamp operation happen? Verify with getApplicationCpuTimeLimit on hardware + percentage = std::clamp(percentage, 5, 89); } + + mem.write32(messagePointer, IPC::responseHeader(0x4F, 1, 0)); + mem.write32(messagePointer + 4, Result::Success); + cpuTimeLimit = percentage; } void APTService::getApplicationCpuTimeLimit(u32 messagePointer) {