From 7a0fdd19a0caca23fc6f591339caea829785e7b4 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 7 Feb 2025 13:06:43 -0500 Subject: [PATCH] kernel/sem: Properly handle create_sem being called with a negative count. It doesn't make much sense to do this, and the Be Book specifies that doing so will return an error. A user on the mailing list tested against BeOS and confirmed that it does reject this, so we should too. --- src/system/kernel/sem.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/system/kernel/sem.cpp b/src/system/kernel/sem.cpp index 0755a4ee77..a1b1ab7d99 100644 --- a/src/system/kernel/sem.cpp +++ b/src/system/kernel/sem.cpp @@ -468,6 +468,8 @@ haiku_sem_init(kernel_args *args) sem_id create_sem_etc(int32 count, const char* name, team_id owner) { + if (count < 0) + return B_BAD_VALUE; if (!sSemsActive || sUsedSems == sMaxSems) return B_NO_MORE_SEMS;