Skip to content

Commit 7191b64

Browse files
yonschnashif
authored andcommitted
gen_isr_tables: Added check of the IRQ num before accessing the vt
At its current state, the script tries to access the vector table list without checking first that the index is valid. This can cause the script to crash without a descriptive message. The index can be invalid if an IRQ number that is larger than the maximum number allowed by the SOC is used. This PR adds a check of that index, that exits with an error message if the index is invalid. Fixes #29809 Signed-off-by: Yonatan Schachter <[email protected]>
1 parent b6b6d39 commit 7191b64

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

arch/common/gen_isr_tables.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def main():
259259
if param != 0:
260260
error("Direct irq %d declared, but has non-NULL parameter"
261261
% irq)
262+
if not 0 <= irq - offset < len(vt):
263+
error("IRQ %d (offset=%d) exceeds the maximum of %d" %
264+
(irq - offset, offset, len(vt) - 1))
262265
vt[irq - offset] = func
263266
else:
264267
# Regular interrupt
@@ -302,6 +305,9 @@ def main():
302305
debug('IRQ_Pos = ' + str(irq1))
303306
table_index = irq1 - offset
304307

308+
if not 0 <= table_index < len(swt):
309+
error("IRQ %d (offset=%d) exceeds the maximum of %d" %
310+
(table_index, offset, len(swt) - 1))
305311
if swt[table_index] != (0, spurious_handler):
306312
error(f"multiple registrations at table_index {table_index} for irq {irq} (0x{irq:x})"
307313
+ f"\nExisting handler 0x{swt[table_index][1]:x}, new handler 0x{func:x}"

0 commit comments

Comments
 (0)