aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/sd/sd.c2
-rw-r--r--tests/qtest/fuzz-sdcard-test.c36
2 files changed, 37 insertions, 1 deletions
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 707dcc1..bb5dbff 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -821,7 +821,6 @@ 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) {
/*
* If the addresses of the last groups are outside the valid range,
@@ -829,6 +828,7 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr)
*/
continue;
}
+ assert(wpnum < sd->wpgrps_size);
if (test_bit(wpnum, sd->wp_groups)) {
ret |= (1 << i);
}
diff --git a/tests/qtest/fuzz-sdcard-test.c b/tests/qtest/fuzz-sdcard-test.c
index 96602ea..ae14305 100644
--- a/tests/qtest/fuzz-sdcard-test.c
+++ b/tests/qtest/fuzz-sdcard-test.c
@@ -52,6 +52,41 @@ static void oss_fuzz_29225(void)
qtest_quit(s);
}
+/*
+ * https://gitlab.com/qemu-project/qemu/-/issues/495
+ * Used to trigger:
+ * Assertion `wpnum < sd->wpgrps_size' failed.
+ */
+static void oss_fuzz_36217(void)
+{
+ QTestState *s;
+
+ s = qtest_init(" -display none -m 32 -nodefaults -nographic"
+ " -device sdhci-pci,sd-spec-version=3 "
+ "-device sd-card,drive=d0 "
+ "-drive if=none,index=0,file=null-co://,format=raw,id=d0");
+
+ qtest_outl(s, 0xcf8, 0x80001010);
+ qtest_outl(s, 0xcfc, 0xe0000000);
+ qtest_outl(s, 0xcf8, 0x80001004);
+ qtest_outw(s, 0xcfc, 0x02);
+ qtest_bufwrite(s, 0xe000002c, "\x05", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x37", 0x1);
+ qtest_bufwrite(s, 0xe000000a, "\x01", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x29", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x02", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x03", 0x1);
+ qtest_bufwrite(s, 0xe0000005, "\x01", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x06", 0x1);
+ qtest_bufwrite(s, 0xe000000c, "\x05", 0x1);
+ qtest_bufwrite(s, 0xe000000e, "\x20", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x08", 0x1);
+ qtest_bufwrite(s, 0xe000000b, "\x3d", 0x1);
+ qtest_bufwrite(s, 0xe000000f, "\x1e", 0x1);
+
+ qtest_quit(s);
+}
+
int main(int argc, char **argv)
{
const char *arch = qtest_get_arch();
@@ -60,6 +95,7 @@ int main(int argc, char **argv)
if (strcmp(arch, "i386") == 0) {
qtest_add_func("fuzz/sdcard/oss_fuzz_29225", oss_fuzz_29225);
+ qtest_add_func("fuzz/sdcard/oss_fuzz_36217", oss_fuzz_36217);
}
return g_test_run();