[PATCH] cmdQemuMonitorCommandQMPWrap: Reset ignored errors from JSON parsing

Peter Krempa pkrempa at redhat.com
Tue Mar 1 13:33:28 UTC 2022

'cmdQemuMonitorCommandQMPWrap' is checking whether the user provided
string is not valid JSON to avoid wrapping it. In cases where it's not
JSON we ignore the error and add the wrapper.

If the caller then reports a different non-libvirt error the error from
the JSON parsing would be printed as well. Reset errors we ignore:

 # virsh qemu-monitor-command cd --pass-fds a asdf
 error: Unable to parse FD number 'a'
 error: internal error: cannot parse json asdf: lexical error: invalid char in json text.
                      (right here) ------^

In the above case 'asdf' is not valid JSON, but the code did wrap it
into '{"execute":"asdf"}', the only problem is the argument for

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
 tools/virsh-domain.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 9b1b14cdc2..743660e794 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9769,6 +9769,8 @@ cmdQemuMonitorCommandQMPWrap(vshControl *ctl,
     if (virJSONValueIsObject(fullcmdjson))
         return g_steal_pointer(&fullcmd);

+    vshResetLibvirtError();
     /* we try to wrap the command and possible arguments into a JSON object, if
      * we as fall back we pass through what we've got from the user */

@@ -9787,6 +9789,8 @@ cmdQemuMonitorCommandQMPWrap(vshControl *ctl,
          * JSON object wrapper and try using that */
         g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;

+        vshResetLibvirtError();
         virBufferAddLit(&buf, "{");
         /* opt points to the _ARGV option bit containing the command so we'll
          * iterate through the arguments now */

More information about the libvir-list mailing list