958e1b
From 55355b00b588e875583e2463beac3d5d1b53ac35 Mon Sep 17 00:00:00 2001
958e1b
From: Kevin Wolf <kwolf@redhat.com>
958e1b
Date: Thu, 23 Oct 2014 10:10:07 +0200
958e1b
Subject: [PATCH 04/19] blockdev: Fix NULL pointer dereference in blockdev-add
958e1b
958e1b
Message-id: <1414059011-15516-5-git-send-email-kwolf@redhat.com>
958e1b
Patchwork-id: 61838
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v2 4/8] blockdev: Fix NULL pointer dereference in blockdev-add
958e1b
Bugzilla: 1088176
958e1b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
If aio=native, we check that cache.direct is set as well. If however
958e1b
cache wasn't specified at all, qemu just segfaulted.
958e1b
958e1b
The old condition didn't make any sense anyway because it effectively
958e1b
only checked for the default cache mode case, but not for an explicitly
958e1b
set cache.direct=off mode.
958e1b
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
Reviewed-by: Benoit Canet <benoit@irqsave.net>
958e1b
Reviewed-by: Eric Blake <eblake@redhat.com>
958e1b
(cherry picked from commit c6e0bd9b7037937aafeb1d34ec17975a7d685bb7)
958e1b
958e1b
Trivial bonus bugfix so that the backported test 087 won't fail.
958e1b
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 blockdev.c | 6 ++++--
958e1b
 1 file changed, 4 insertions(+), 2 deletions(-)
958e1b
958e1b
diff --git a/blockdev.c b/blockdev.c
958e1b
index a2d5f02..1ac8804 100644
958e1b
--- a/blockdev.c
958e1b
+++ b/blockdev.c
958e1b
@@ -1810,8 +1810,10 @@ void qmp_blockdev_add(BlockdevOptions *options, Error **errp)
958e1b
      *
958e1b
      * For now, simply forbidding the combination for all drivers will do. */
958e1b
     if (options->has_aio && options->aio == BLOCKDEV_AIO_OPTIONS_NATIVE) {
958e1b
-        bool direct = options->cache->has_direct && options->cache->direct;
958e1b
-        if (!options->has_cache && !direct) {
958e1b
+        bool direct = options->has_cache &&
958e1b
+                      options->cache->has_direct &&
958e1b
+                      options->cache->direct;
958e1b
+        if (!direct) {
958e1b
             error_setg(errp, "aio=native requires cache.direct=true");
958e1b
             goto fail;
958e1b
         }
958e1b
-- 
958e1b
1.8.3.1
958e1b