mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 01:21:26 +08:00
sched/irq: Avoid negative array index in irqchain_dispatch
IRQ_TO_NDX() may return a negative value when the IRQ number is invalid or not mapped. Using this negative value directly as an array index for g_irqvector causes undefined behavior and potential memory corruption. This patch adds a bounds check to ensure ndx is non-negative before accessing the g_irqvector array, returning the error code if invalid. Signed-off-by: pangzhen1 <pangzhen1@xiaomi.com>
This commit is contained in:
@@ -80,6 +80,12 @@ static int irqchain_dispatch(int irq, FAR void *context, FAR void *arg)
|
|||||||
int ndx = IRQ_TO_NDX(irq);
|
int ndx = IRQ_TO_NDX(irq);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (ndx < 0)
|
||||||
|
{
|
||||||
|
ret = ndx;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
curr = g_irqvector[ndx].arg;
|
curr = g_irqvector[ndx].arg;
|
||||||
while (curr != NULL)
|
while (curr != NULL)
|
||||||
{
|
{
|
||||||
@@ -87,6 +93,7 @@ static int irqchain_dispatch(int irq, FAR void *context, FAR void *arg)
|
|||||||
curr = curr->next;
|
curr = curr->next;
|
||||||
ret |= prev->handler(irq, context, prev->arg);
|
ret |= prev->handler(irq, context, prev->arg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user