From f2f2572fed075d2dca5ae7abcea451ac5eb382ec Mon Sep 17 00:00:00 2001 From: Subv Date: Wed, 11 Jan 2017 12:08:10 -0500 Subject: Thread: Added priority range checking to svcSetThreadPriority and removed priority clamping code from Thread::SetPriority. --- src/core/hle/svc.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 2b242ff98..8cb6a1c94 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -598,10 +598,24 @@ static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { /// Sets the priority for the specified thread static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { + if (priority > THREADPRIO_LOWEST) { + return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage); + } + SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; + using Kernel::ResourceLimit; + // Note: The kernel uses the current process's resource limit instead of + // the one from the thread owner's resource limit. + Kernel::SharedPtr& resource_limit = Kernel::g_current_process->resource_limit; + if (resource_limit->GetMaxResourceValue(Kernel::ResourceTypes::PRIORITY) > priority) { + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::OS, + ErrorSummary::WrongArgument, ErrorLevel::Permanent); + } + thread->SetPriority(priority); thread->UpdatePriority(); -- cgit v1.2.3