This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 3650636e393 sched/irq: Avoid out-of-bounds array access
3650636e393 is described below

commit 3650636e3938a71b4041d338b850ddd1e303c864
Author: pangzhen1 <[email protected]>
AuthorDate: Thu Aug 14 15:19:42 2025 +0800

    sched/irq: Avoid out-of-bounds array access
    
    This patch fixes an array out-of-bounds access issue in the 
irq_get_wqueue() function.
    
    Signed-off-by: pangzhen1 <[email protected]>
---
 sched/irq/irq_attach_wqueue.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/sched/irq/irq_attach_wqueue.c b/sched/irq/irq_attach_wqueue.c
index 9ca431e7011..783629b9f01 100644
--- a/sched/irq/irq_attach_wqueue.c
+++ b/sched/irq/irq_attach_wqueue.c
@@ -80,7 +80,7 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int 
priority)
   int i;
 
   nxmutex_lock(&irq_wqueue_lock);
-  for (i = 0; irq_wqueue[i] != NULL && i < CONFIG_IRQ_NWORKS; i++)
+  for (i = 0; i < CONFIG_IRQ_NWORKS && irq_wqueue[i] != NULL; i++)
     {
       wqueue_priority = work_queue_priority_wq(irq_wqueue[i]);
       DEBUGASSERT(wqueue_priority >= SCHED_PRIORITY_MIN &&
@@ -94,9 +94,7 @@ inline_function FAR struct kwork_wqueue_s *irq_get_wqueue(int 
priority)
         }
     }
 
-  DEBUGASSERT(i < CONFIG_IRQ_NWORKS);
-
-  if (queue == NULL)
+  if (i < CONFIG_IRQ_NWORKS && queue == NULL)
     {
       queue = work_queue_create("isrwork", priority, irq_work_stack[i],
                                 CONFIG_IRQ_WORK_STACKSIZE, 1);

Reply via email to