On 03/30/2017 02:50 AM, Thomas Huth wrote: > HMP commands do not get any automatic testing yet, so on certain > QEMU machines, some HMP commands were causing crashes in the past. > Thus we should test HMP commands in our test suite, too, to avoid > that such problems creep in again in the future. > > Signed-off-by: Thomas Huth <[email protected]> > ---
> +static const char *hmp_cmds[] = {
> + "boot_set ndc",
> +/* Run through the list of pre-defined commands */
> +static void test_commands(void)
> +{
> + char *response;
> + int i;
> +
> + for (i = 0; hmp_cmds[i] != NULL; i++) {
> + if (verbose) {
> + fprintf(stderr, "\t%s\n", hmp_cmds[i]);
> + }
> + response = hmp(hmp_cmds[i]);
I failed to notice this sooner, but hmp() is passing its first arg as a
format string through a printf family. If hmp_cmds[i] ever gets
modified to include something with a %, it will misbehave. Better is to
use hmp("%s", variable).
I've patched it locally as part of rebasing my work on avoiding dynamic
JSON format strings, if no one beats me to a fix (my series also adds
the gcc format attribute tag, so that the compiler catches any further
mismatches in hmp() format vs. arguments).
> + while (*info) {
> + /* Extract the info command, ignore parameters and description */
> + g_assert(strncmp(info, "info ", 5) == 0);
> + endp = strchr(&info[5], ' ');
> + g_assert(endp != NULL);
> + *endp = '\0';
> + /* Now run the info command */
> + if (verbose) {
> + fprintf(stderr, "\t%s\n", info);
> + }
> + resp = hmp(info);
Another instance.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
