]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virqemu: Don't strip the requested key from nested objects
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Dec 2022 16:00:26 +0000 (17:00 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 4 Jan 2023 13:01:16 +0000 (14:01 +0100)
Skipping of a specific key is needed only for the top level object to
specially handle the object type. We must not pass it to any recursed
printing of nested objects as skipping keys there might be surprising
and also is unhandlable later when formatting the commandline.

Until now this did not pose a problem but was discovered when adding a
new netdev backend which has a nested config object which also has the
'type' key which was being skipped.

Modern usage will prefer JSON directly but fix the commandline generator
to prevent surprises.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virqemu.c

index 9dc0eab386a88231436ecc2434ffaaec6edcce92..15602e30db339944782e318a517aed91a7dfca4f 100644 (file)
@@ -163,8 +163,7 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
     if (data->prefix)
         key = tmpkey = g_strdup_printf("%s.%s", data->prefix, key);
 
-    return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
-                                              data->skipKey,
+    return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf, NULL,
                                               data->arrayFunc, false);
 }
 
@@ -222,14 +221,14 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
             return -1;
         }
 
-        if (arrayFunc(key, value, buf, skipKey) < 0) {
+        if (arrayFunc(key, value, buf, NULL) < 0) {
             /* fallback, treat the array as a non-bitmap, adding the key
              * for each member */
             for (i = 0; i < virJSONValueArraySize(value); i++) {
                 elem = virJSONValueArrayGet((virJSONValue *)value, i);
 
                 /* recurse to avoid duplicating code */
-                if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, skipKey,
+                if (virQEMUBuildCommandLineJSONRecurse(key, elem, buf, NULL,
                                                        arrayFunc, true) < 0)
                     return -1;
             }
@@ -257,7 +256,8 @@ virQEMUBuildCommandLineJSONRecurse(const char *key,
  * virQEMUBuildCommandLineJSON:
  * @value: json object containing the value
  * @buf: otuput buffer
- * @skipKey: name of key that will be handled separately by caller
+ * @skipKey: name of key inside the top level object that will be handled
+ *           separately by caller
  * @arrayFunc: array formatter function to allow for different syntax
  *
  * Formats JSON value object into command line parameters suitable for use with