Skip to content

Commit 8be1cb3

Browse files
rgundinashif
authored andcommitted
lib/cmsis_rtos_v1: Fix boundary conditions in the signals module
Fixed the boundary conditions around osFeature_Signals. Fixes #9857. Signed-off-by: Rajavardhan Gundi <[email protected]>
1 parent 1b03916 commit 8be1cb3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/cmsis_rtos_v1/cmsis_signal.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <kernel_structs.h>
88
#include <cmsis_os.h>
99

10-
#define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC)
10+
#define NSEC_PER_MSEC (NSEC_PER_USEC * USEC_PER_MSEC)
11+
#define MAX_VALID_SIGNAL_VAL ((1 << osFeature_Signals) - 1)
1112

1213
void *k_thread_other_custom_data_get(struct k_thread *thread_id)
1314
{
@@ -22,7 +23,7 @@ int32_t osSignalSet(osThreadId thread_id, int32_t signals)
2223
int sig, key;
2324

2425
if ((thread_id == NULL) || (!signals) ||
25-
(signals >= (1 << (osFeature_Signals + 1)))) {
26+
(signals & 0x80000000) || (signals > MAX_VALID_SIGNAL_VAL)) {
2627
return 0x80000000;
2728
}
2829

@@ -48,7 +49,7 @@ int32_t osSignalClear(osThreadId thread_id, int32_t signals)
4849
int sig, key;
4950

5051
if (_is_in_isr() || (thread_id == NULL) || (!signals) ||
51-
(signals >= (1 << (osFeature_Signals + 1)))) {
52+
(signals & 0x80000000) || (signals > MAX_VALID_SIGNAL_VAL)) {
5253
return 0x80000000;
5354
}
5455

@@ -81,7 +82,7 @@ osEvent osSignalWait(int32_t signals, uint32_t millisec)
8182
}
8283

8384
/* Check if signals is within the permitted range */
84-
if (signals >= (1 << (osFeature_Signals + 1))) {
85+
if ((signals & 0x80000000) || (signals > MAX_VALID_SIGNAL_VAL)) {
8586
evt.status = osErrorValue;
8687
return evt;
8788
}

0 commit comments

Comments
 (0)