Skip to content

Commit

Permalink
Merge pull request #350 from wheremyfoodat/zep
Browse files Browse the repository at this point in the history
[APT] Gracefully handle SetApplicationCpuTimeLimit with invalid inputs
  • Loading branch information
wheremyfoodat authored Dec 16, 2023
2 parents 385a223 + 18f1ea5 commit 03292b5
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/core/services/apt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ipc.hpp"
#include "kernel.hpp"

#include <algorithm>
#include <vector>

namespace APTCommands {
Expand Down Expand Up @@ -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<u32>(percentage, 5, 89);
}

mem.write32(messagePointer, IPC::responseHeader(0x4F, 1, 0));
mem.write32(messagePointer + 4, Result::Success);
cpuTimeLimit = percentage;
}

void APTService::getApplicationCpuTimeLimit(u32 messagePointer) {
Expand Down

0 comments on commit 03292b5

Please sign in to comment.