riscv: treat undefined exception codes as reserved
authorLukas Auer <lukas.auer@aisec.fraunhofer.de>
Thu, 22 Nov 2018 10:26:21 +0000 (11:26 +0100)
committerAndes <uboot@andestech.com>
Mon, 26 Nov 2018 05:57:30 +0000 (13:57 +0800)
Undefined exception codes currently lead to an out-of-bounds array
access. Prevent this by treating undefined exception codes as
"reserved".

Signed-off-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Rick Chen <rick@andestech.com>
arch/riscv/lib/interrupts.c

index 6a12818c2b225aaea183489820930eedf0ec0103..d0d8de500ee65e31a32a61ad7638f4bc2d47348d 100644 (file)
@@ -81,6 +81,10 @@ static void _exit_trap(ulong code, ulong epc, struct pt_regs *regs)
                "Store/AMO page fault",
        };
 
-       printf("exception code: %ld , %s , epc %lx , ra %lx\n",
-               code, exception_code[code], epc, regs->ra);
+       if (code < ARRAY_SIZE(exception_code)) {
+               printf("exception code: %ld , %s , epc %lx , ra %lx\n",
+                      code, exception_code[code], epc, regs->ra);
+       } else {
+               printf("Reserved\n");
+       }
 }