Blame SOURCES/libvirt-storage-Don-t-dereference-driver-object-if-virStorageSource-is-not-initialized.patch

c1c534
From ef9bacb8ce672161449683f748d4df76c4b78a54 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <ef9bacb8ce672161449683f748d4df76c4b78a54@dist-git>
c1c534
From: Peter Krempa <pkrempa@redhat.com>
c1c534
Date: Thu, 7 Dec 2017 13:45:50 +0100
c1c534
Subject: [PATCH] storage: Don't dereference driver object if virStorageSource
c1c534
 is not initialized
c1c534
c1c534
virStorageFileReportBrokenChain uses data from the driver private data
c1c534
pointer to print the user and group. This would lead to a crash in call
c1c534
paths where we did not initialize the storage backend as recently added
c1c534
in commit 24e47ee2b93 to qemuDomainDetermineDiskChain.
c1c534
c1c534
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1522682
c1c534
(cherry picked from commit 2d07f1f0ebd44b0348daa61afa0de34f3f838c22)
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/storage/storage_source.c | 36 +++++++++++++++++++++++++-----------
c1c534
 1 file changed, 25 insertions(+), 11 deletions(-)
c1c534
c1c534
diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c
c1c534
index 469d3a00bc..aaec988e9a 100644
c1c534
--- a/src/storage/storage_source.c
c1c534
+++ b/src/storage/storage_source.c
c1c534
@@ -404,19 +404,33 @@ virStorageFileReportBrokenChain(int errcode,
c1c534
                                 virStorageSourcePtr src,
c1c534
                                 virStorageSourcePtr parent)
c1c534
 {
c1c534
-    unsigned int access_user = src->drv->uid;
c1c534
-    unsigned int access_group = src->drv->gid;
c1c534
 
c1c534
-    if (src == parent) {
c1c534
-        virReportSystemError(errcode,
c1c534
-                             _("Cannot access storage file '%s' "
c1c534
-                               "(as uid:%u, gid:%u)"),
c1c534
-                             src->path, access_user, access_group);
c1c534
+    if (src->drv) {
c1c534
+        unsigned int access_user = src->drv->uid;
c1c534
+        unsigned int access_group = src->drv->gid;
c1c534
+
c1c534
+        if (src == parent) {
c1c534
+            virReportSystemError(errcode,
c1c534
+                                 _("Cannot access storage file '%s' "
c1c534
+                                   "(as uid:%u, gid:%u)"),
c1c534
+                                 src->path, access_user, access_group);
c1c534
+        } else {
c1c534
+            virReportSystemError(errcode,
c1c534
+                                 _("Cannot access backing file '%s' "
c1c534
+                                   "of storage file '%s' (as uid:%u, gid:%u)"),
c1c534
+                                 src->path, parent->path, access_user, access_group);
c1c534
+        }
c1c534
     } else {
c1c534
-        virReportSystemError(errcode,
c1c534
-                             _("Cannot access backing file '%s' "
c1c534
-                               "of storage file '%s' (as uid:%u, gid:%u)"),
c1c534
-                             src->path, parent->path, access_user, access_group);
c1c534
+        if (src == parent) {
c1c534
+            virReportSystemError(errcode,
c1c534
+                                 _("Cannot access storage file '%s'"),
c1c534
+                                 src->path);
c1c534
+        } else {
c1c534
+            virReportSystemError(errcode,
c1c534
+                                 _("Cannot access backing file '%s' "
c1c534
+                                   "of storage file '%s'"),
c1c534
+                                 src->path, parent->path);
c1c534
+        }
c1c534
     }
c1c534
 }
c1c534
 
c1c534
-- 
c1c534
2.15.1
c1c534