From 661a71885b5209fe5b76c5bb9628644b883d3974 Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 21 Nov 2024 12:32:18 +0300 Subject: [PATCH] kernel:fix sys_osem_trywait merge issue fix sys_osem_post on wrong descriptor --- orbis-kernel/src/sys/sys_sce.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/orbis-kernel/src/sys/sys_sce.cpp b/orbis-kernel/src/sys/sys_sce.cpp index 977ce85..ac118dc 100644 --- a/orbis-kernel/src/sys/sys_sce.cpp +++ b/orbis-kernel/src/sys/sys_sce.cpp @@ -609,7 +609,9 @@ orbis::SysResult orbis::sys_osem_trywait(Thread *thread, sint id, sint need) { return ErrorCode::BADF; } + if (need < 1 || need > sem->maxValue) { return ErrorCode::INVAL; + } std::lock_guard lock(sem->mtx); if (sem->isDeleted || sem->value < need) @@ -620,8 +622,12 @@ orbis::SysResult orbis::sys_osem_trywait(Thread *thread, sint id, sint need) { orbis::SysResult orbis::sys_osem_post(Thread *thread, sint id, sint count) { ORBIS_LOG_TRACE(__FUNCTION__, thread, id, count); Ref sem = thread->tproc->semMap.get(id); - if (count < 1 || count > sem->maxValue - sem->value) + if (sem == nullptr) { + return ErrorCode::BADF; + } + if (count < 1 || count > sem->maxValue - sem->value) { return ErrorCode::INVAL; + } std::lock_guard lock(sem->mtx); if (sem->isDeleted)