qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 3/3] tests: Add a tester for HMP commands


From: Dr. David Alan Gilbert
Subject: Re: [Qemu-devel] [PATCH v2 3/3] tests: Add a tester for HMP commands
Date: Thu, 29 Jun 2017 12:48:32 +0100
User-agent: Mutt/1.8.3 (2017-05-23)

* Eric Blake (address@hidden) wrote:
> 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 <address@hidden>
> > ---
> 
> > +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).

Ah yes, good spot.  Please include that fix.

Dave

> > +    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
> 



--
Dr. David Alan Gilbert / address@hidden / Manchester, UK



reply via email to

[Prev in Thread] Current Thread [Next in Thread]