cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-block-Make-remaining-uses-of-qobject-input-visitor-m.patch

26ba25
From d8f04a096c6c5ec035c17ef41e1af1801beb27a6 Mon Sep 17 00:00:00 2001
26ba25
From: Markus Armbruster <armbru@redhat.com>
26ba25
Date: Mon, 18 Jun 2018 08:43:21 +0200
26ba25
Subject: [PATCH 023/268] block: Make remaining uses of qobject input visitor
26ba25
 more robust
26ba25
26ba25
RH-Author: Markus Armbruster <armbru@redhat.com>
26ba25
Message-id: <20180618084330.30009-15-armbru@redhat.com>
26ba25
Patchwork-id: 80730
26ba25
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 14/23] block: Make remaining uses of qobject input visitor more robust
26ba25
Bugzilla: 1557995
26ba25
RH-Acked-by: Max Reitz <mreitz@redhat.com>
26ba25
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
26ba25
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
26ba25
26ba25
Remaining uses of qobject_input_visitor_new_keyval() in the block
26ba25
subsystem:
26ba25
26ba25
* block_crypto_open_opts_init()
26ba25
  Currently doesn't visit any non-string scalars, thus safe.  It's
26ba25
  called from
26ba25
  - block_crypto_open_luks()
26ba25
    Creates the QDict with qemu_opts_to_qdict_filtered(), which
26ba25
    creates only string scalars, but has a TODO asking for other types.
26ba25
  - qcow_open()
26ba25
  - qcow2_open(), qcow2_co_invalidate_cache(), qcow2_reopen_prepare()
26ba25
26ba25
* block_crypto_create_opts_init(), called from
26ba25
  - block_crypto_co_create_opts_luks()
26ba25
    Also creates the QDict with qemu_opts_to_qdict_filtered().
26ba25
26ba25
* vdi_co_create_opts()
26ba25
  Also creates the QDict with qemu_opts_to_qdict_filtered().
26ba25
26ba25
Replace these uses by qobject_input_visitor_new_flat_confused() for
26ba25
robustness.  This adds crumpling.  Right now, that's a no-op, but if
26ba25
we ever extend these things in non-flat ways, crumpling will be
26ba25
needed.
26ba25
26ba25
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26ba25
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
26ba25
(cherry picked from commit f853465aacb45dbb07e4cc9815e39b55e10dc690)
26ba25
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
26ba25
---
26ba25
 block/crypto.c | 12 +++++++++---
26ba25
 block/vdi.c    |  8 ++++++--
26ba25
 2 files changed, 15 insertions(+), 5 deletions(-)
26ba25
26ba25
diff --git a/block/crypto.c b/block/crypto.c
26ba25
index 7e7ad2d..f5151f4 100644
26ba25
--- a/block/crypto.c
26ba25
+++ b/block/crypto.c
26ba25
@@ -21,11 +21,11 @@
26ba25
 #include "qemu/osdep.h"
26ba25
 
26ba25
 #include "block/block_int.h"
26ba25
+#include "block/qdict.h"
26ba25
 #include "sysemu/block-backend.h"
26ba25
 #include "crypto/block.h"
26ba25
 #include "qapi/opts-visitor.h"
26ba25
 #include "qapi/qapi-visit-crypto.h"
26ba25
-#include "qapi/qmp/qdict.h"
26ba25
 #include "qapi/qobject-input-visitor.h"
26ba25
 #include "qapi/error.h"
26ba25
 #include "qemu/option.h"
26ba25
@@ -159,7 +159,10 @@ block_crypto_open_opts_init(QCryptoBlockFormat format,
26ba25
     ret = g_new0(QCryptoBlockOpenOptions, 1);
26ba25
     ret->format = format;
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(opts));
26ba25
+    v = qobject_input_visitor_new_flat_confused(opts, &local_err);
26ba25
+    if (local_err) {
26ba25
+        goto out;
26ba25
+    }
26ba25
 
26ba25
     visit_start_struct(v, NULL, NULL, 0, &local_err);
26ba25
     if (local_err) {
26ba25
@@ -210,7 +213,10 @@ block_crypto_create_opts_init(QCryptoBlockFormat format,
26ba25
     ret = g_new0(QCryptoBlockCreateOptions, 1);
26ba25
     ret->format = format;
26ba25
 
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(opts));
26ba25
+    v = qobject_input_visitor_new_flat_confused(opts, &local_err);
26ba25
+    if (local_err) {
26ba25
+        goto out;
26ba25
+    }
26ba25
 
26ba25
     visit_start_struct(v, NULL, NULL, 0, &local_err);
26ba25
     if (local_err) {
26ba25
diff --git a/block/vdi.c b/block/vdi.c
26ba25
index 96a22b8..41859a8 100644
26ba25
--- a/block/vdi.c
26ba25
+++ b/block/vdi.c
26ba25
@@ -51,10 +51,10 @@
26ba25
 
26ba25
 #include "qemu/osdep.h"
26ba25
 #include "qapi/error.h"
26ba25
-#include "qapi/qmp/qdict.h"
26ba25
 #include "qapi/qobject-input-visitor.h"
26ba25
 #include "qapi/qapi-visit-block-core.h"
26ba25
 #include "block/block_int.h"
26ba25
+#include "block/qdict.h"
26ba25
 #include "sysemu/block-backend.h"
26ba25
 #include "qemu/module.h"
26ba25
 #include "qemu/option.h"
26ba25
@@ -933,7 +933,11 @@ static int coroutine_fn vdi_co_create_opts(const char *filename, QemuOpts *opts,
26ba25
     }
26ba25
 
26ba25
     /* Get the QAPI object */
26ba25
-    v = qobject_input_visitor_new_keyval(QOBJECT(qdict));
26ba25
+    v = qobject_input_visitor_new_flat_confused(qdict, errp);
26ba25
+    if (!v) {
26ba25
+        ret = -EINVAL;
26ba25
+        goto done;
26ba25
+    }
26ba25
     visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
26ba25
     visit_free(v);
26ba25
 
26ba25
-- 
26ba25
1.8.3.1
26ba25