fuzz: Expect the cmdline in a freeable GString

In the initial FuzzTarget, get_init_cmdline returned a char *. With this
API, we had no guarantee about where the string came from. For example,
i440fx-qtest-reboot-fuzz simply returned a pointer to a string literal,
while the QOS-based targets build the arguments out in a GString an
return the gchar *str pointer. Since we did not try to free the cmdline,
we have a leak for any targets that do not simply return string
literals. Clean up this mess by forcing fuzz-targets to return
a GString, that we can free.

Signed-off-by: Alexander Bulekov <alxndr@bu.edu>
Message-Id: <20200714174616.20709-1-alxndr@bu.edu>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Alexander Bulekov 2020-07-14 13:46:16 -04:00 committed by Thomas Huth
parent 15c51f724e
commit f5ec79f5e0
4 changed files with 14 additions and 15 deletions

View file

@ -199,16 +199,15 @@ int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp)
}
/* Run QEMU's softmmu main with the fuzz-target dependent arguments */
const char *init_cmdline = fuzz_target->get_init_cmdline(fuzz_target);
init_cmdline = g_strdup_printf("%s -qtest /dev/null -qtest-log %s",
init_cmdline,
getenv("QTEST_LOG") ? "/dev/fd/2"
: "/dev/null");
GString *cmd_line = fuzz_target->get_init_cmdline(fuzz_target);
g_string_append_printf(cmd_line,
" -qtest /dev/null -qtest-log %s",
getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null");
/* Split the runcmd into an argv and argc */
wordexp_t result;
wordexp(init_cmdline, &result, 0);
wordexp(cmd_line->str, &result, 0);
g_string_free(cmd_line, true);
qemu_init(result.we_wordc, result.we_wordv, NULL);