Skip to contentSkip to conversation

hw/omap_intc.c: Avoid crash on access to nonexistent banked registers

PATCH Applied Peter Maydell 2 participants 2 messages Nov 9, 2011 – Nov 11, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/omap_intc.c: Avoid crash on access to nonexistent banked registers

Avoid a crash due to null pointer dereference if a guest attempts to access banked registers for a nonexistent bank. Spotted by Coverity (see bug 887883).

---
 hw/omap_intc.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
hw/omap_intc.c +6 -0
index 0f7fd9d..45efa25 100644
@@ -398,6 +398,9 @@ static uint64_t omap2_inth_read(void *opaque, target_phys_addr_t addr,
         if (bank_no < s->nbanks) {
             offset &= ~0x60;
             bank = &s->bank[bank_no];
+        } else {
+            OMAP_BAD_REG(addr);
+            return 0;
         }
     }
 
@@ -476,6 +479,9 @@ static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
         if (bank_no < s->nbanks) {
             offset &= ~0x60;
             bank = &s->bank[bank_no];
+        } else {
+            OMAP_BAD_REG(addr);
+            return;
         }
     }
 
Signature · 1 line
1.7.1
#1 lore raw
Quoted 5 lines · Peter Maydell

Avoid a crash due to null pointer dereference if a guest attempts to access banked registers for a nonexistent bank. Spotted by Coverity (see bug 887883).

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 28 lines
---
  hw/omap_intc.c |    6 ++++++
  1 files changed, 6 insertions(+), 0 deletions(-)
hw/omap_intc.c +6 -0
index 0f7fd9d..45efa25 100644
@@ -398,6 +398,9 @@ static uint64_t omap2_inth_read(void *opaque, target_phys_addr_t addr,
          if (bank_no<  s->nbanks) {
              offset&= ~0x60;
              bank =&s->bank[bank_no];
+        } else {
+            OMAP_BAD_REG(addr);
+            return 0;
          }
      }
 
@@ -476,6 +479,9 @@ static void omap2_inth_write(void *opaque, target_phys_addr_t addr,
          if (bank_no<  s->nbanks) {
              offset&= ~0x60;
              bank =&s->bank[bank_no];
+        } else {
+            OMAP_BAD_REG(addr);
+            return;
          }
      }