xref: /openbmc/qemu/tests/qtest/fuzz-sdcard-test.c (revision 96916f36)
1 /*
2  * QTest fuzzer-generated testcase for sdcard device
3  *
4  * Copyright (c) 2021 Philippe Mathieu-Daudé <f4bug@amsat.org>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "qemu/osdep.h"
10 #include "libqos/libqtest.h"
11 
12 /*
13  * https://gitlab.com/qemu-project/qemu/-/issues/450
14  * Used to trigger:
15  *  Assertion `wpnum < sd->wpgrps_size' failed.
16  */
17 static void oss_fuzz_29225(void)
18 {
19     QTestState *s;
20 
21     s = qtest_init(" -display none -m 512m -nodefaults -nographic"
22                    " -device sdhci-pci,sd-spec-version=3"
23                    " -device sd-card,drive=d0"
24                    " -drive if=none,index=0,file=null-co://,format=raw,id=d0");
25 
26     qtest_outl(s, 0xcf8, 0x80001010);
27     qtest_outl(s, 0xcfc, 0xd0690);
28     qtest_outl(s, 0xcf8, 0x80001003);
29     qtest_outl(s, 0xcf8, 0x80001013);
30     qtest_outl(s, 0xcfc, 0xffffffff);
31     qtest_outl(s, 0xcf8, 0x80001003);
32     qtest_outl(s, 0xcfc, 0x3effe00);
33 
34     qtest_bufwrite(s, 0xff0d062c, "\xff", 0x1);
35     qtest_bufwrite(s, 0xff0d060f, "\xb7", 0x1);
36     qtest_bufwrite(s, 0xff0d060a, "\xc9", 0x1);
37     qtest_bufwrite(s, 0xff0d060f, "\x29", 0x1);
38     qtest_bufwrite(s, 0xff0d060f, "\xc2", 0x1);
39     qtest_bufwrite(s, 0xff0d0628, "\xf7", 0x1);
40     qtest_bufwrite(s, 0x0, "\xe3", 0x1);
41     qtest_bufwrite(s, 0x7, "\x13", 0x1);
42     qtest_bufwrite(s, 0x8, "\xe3", 0x1);
43     qtest_bufwrite(s, 0xf, "\xe3", 0x1);
44     qtest_bufwrite(s, 0xff0d060f, "\x03", 0x1);
45     qtest_bufwrite(s, 0xff0d0605, "\x01", 0x1);
46     qtest_bufwrite(s, 0xff0d060b, "\xff", 0x1);
47     qtest_bufwrite(s, 0xff0d060c, "\xff", 0x1);
48     qtest_bufwrite(s, 0xff0d060e, "\xff", 0x1);
49     qtest_bufwrite(s, 0xff0d060f, "\x06", 0x1);
50     qtest_bufwrite(s, 0xff0d060f, "\x9e", 0x1);
51 
52     qtest_quit(s);
53 }
54 
55 int main(int argc, char **argv)
56 {
57     const char *arch = qtest_get_arch();
58 
59     g_test_init(&argc, &argv, NULL);
60 
61    if (strcmp(arch, "i386") == 0) {
62         qtest_add_func("fuzz/sdcard/oss_fuzz_29225", oss_fuzz_29225);
63    }
64 
65    return g_test_run();
66 }
67