From 5635c1318cfe8f5b4cd0cad75885b26a0293451c Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 7 Jan 2020 17:32:12 +0100 Subject: [PATCH] base-hw: explicit bounds check in store_apic_id Avoid relying on the caller regarding the CPU index argument to ease the reasoning about the code. --- repos/base-hw/src/core/spec/x86_64/pic.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/repos/base-hw/src/core/spec/x86_64/pic.h b/repos/base-hw/src/core/spec/x86_64/pic.h index 7af7a9514..3e0f19128 100644 --- a/repos/base-hw/src/core/spec/x86_64/pic.h +++ b/repos/base-hw/src/core/spec/x86_64/pic.h @@ -209,9 +209,12 @@ class Board::Pic : public Genode::Mmio void irq_mode(unsigned irq, unsigned trigger, unsigned polarity); - void store_apic_id(unsigned const cpu_id) { - Id::access_t const lapic_id = read(); - lapic_ids[cpu_id] = (lapic_id >> 24) & 0xff; + void store_apic_id(unsigned const cpu_id) + { + if (cpu_id < NR_OF_CPUS) { + Id::access_t const lapic_id = read(); + lapic_ids[cpu_id] = (lapic_id >> 24) & 0xff; + } } void send_ipi(unsigned const);