[U-Boot] [PATCH 15/30] riscv: treat undefined exception codes as reserved

Lukas Auer lukas.auer at aisec.fraunhofer.de
Fri Oct 19 22:07:28 UTC 2018


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 at aisec.fraunhofer.de>
---

 arch/riscv/lib/interrupts.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/lib/interrupts.c b/arch/riscv/lib/interrupts.c
index 3d830c3273..32d0598750 100644
--- a/arch/riscv/lib/interrupts.c
+++ b/arch/riscv/lib/interrupts.c
@@ -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 %016lx , ra %016lx\n",
-		code, exception_code[code], epc, regs->ra);
+	if (code < ARRAY_SIZE(exception_code)) {
+		printf("exception code: %ld , %s , epc %016lx , ra %016lx\n",
+		       code, exception_code[code], epc, regs->ra);
+	} else {
+		printf("Reserved\n");
+	}
 }
-- 
2.17.2



More information about the U-Boot mailing list