[libvirt] [PATCH] Sanitize qemu monitor output

Cole Robinson crobinso at redhat.com
Tue Dec 2 16:22:33 UTC 2008

Daniel P. Berrange wrote:
> On Mon, Dec 01, 2008 at 05:36:34PM -0500, Cole Robinson wrote:
>> The attached patch cleans up output we read from the qemu monitor. This
>> is a simplified form of a patch I posted awhile ago. From the patch:
>> /* The monitor doesn't dump clean output after we have written to
>>  * it. Every character we write dumps a bunch of useless stuff,
>>  * so the result looks like "cXcoXcomXcommXcommaXcommanXcommand"
>>  * Try to throw away everything before the first full command
>>  * occurence, and inbetween the command and the newline starting
>>  * the response
>>  */


> This loooks a little overly complex to me, doesn't handle alloction failures
> in strdup correctly & leaks tmpbuf. 

Argh, yeah, I'm always botching this.

>      if ((commptr = strstr(buf, cmd)))
>           memmove(buf, commptr, strlen(commptr)+1);

Yes that's much simpler, though it doesn't take into account the control
characters after the command string and before the newline starting the
command response.

We could just do:

     if ((commptr = strstr(buf, cmd)))
          memmove(buf, commptr, strlen(commptr)+1);
     if ((dupptr = strchr(buf, '\n'))
          memmove(buf+strlen(cmd), dupptr, strlen(dupptr)+1);

I was also trying to avoid having the command string in the 'reply', but
it was an unnecessary restriction.

Updated patch attached. It also fixes an error check from the blockstats
monitor command which wouldn't have worked in the first place, but
should be accurate now.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-monitor-sanitize-2.patch
Type: text/x-patch
Size: 2513 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20081202/7208840e/attachment-0001.bin>

More information about the libvir-list mailing list