]> git.proxmox.com Git - mirror_qemu.git/commitdiff
hw/sd/sdcard: Assert if accessing an illegal group
authorPhilippe Mathieu-Daudé <f4bug@amsat.org>
Fri, 18 Sep 2020 17:14:52 +0000 (19:14 +0200)
committerPhilippe Mathieu-Daudé <f4bug@amsat.org>
Wed, 21 Oct 2020 11:34:27 +0000 (13:34 +0200)
We can not have more group than 'wpgrps_size'.
Assert if we are accessing a group above this limit.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Tested-by: Alexander Bulekov <alxndr@bu.edu>
Message-Id: <20201015063824.212980-7-f4bug@amsat.org>

hw/sd/sd.c

index 4454d168e2fc377668f439c3fa70360581d1f10b..c3febed243468640c9fe828f3db8e616e6fed861 100644 (file)
@@ -780,6 +780,7 @@ static void sd_erase(SDState *sd)
     sd->csd[14] |= 0x40;
 
     for (i = erase_start; i <= erase_end; i++) {
+        assert(i < sd->wpgrps_size);
         if (test_bit(i, sd->wp_groups)) {
             sd->card_status |= WP_ERASE_SKIP;
         }
@@ -794,6 +795,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr)
     wpnum = sd_addr_to_wpnum(addr);
 
     for (i = 0; i < 32; i++, wpnum++, addr += WPGROUP_SIZE) {
+        assert(wpnum < sd->wpgrps_size);
         if (addr < sd->size && test_bit(wpnum, sd->wp_groups)) {
             ret |= (1 << i);
         }