render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From ef9bacb8ce672161449683f748d4df76c4b78a54 Mon Sep 17 00:00:00 2001
Message-Id: <ef9bacb8ce672161449683f748d4df76c4b78a54@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Thu, 7 Dec 2017 13:45:50 +0100
Subject: [PATCH] storage: Don't dereference driver object if virStorageSource
 is not initialized

virStorageFileReportBrokenChain uses data from the driver private data
pointer to print the user and group. This would lead to a crash in call
paths where we did not initialize the storage backend as recently added
in commit 24e47ee2b93 to qemuDomainDetermineDiskChain.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1522682
(cherry picked from commit 2d07f1f0ebd44b0348daa61afa0de34f3f838c22)
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/storage/storage_source.c | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_source.c b/src/storage/storage_source.c
index 469d3a00bc..aaec988e9a 100644
--- a/src/storage/storage_source.c
+++ b/src/storage/storage_source.c
@@ -404,19 +404,33 @@ virStorageFileReportBrokenChain(int errcode,
                                 virStorageSourcePtr src,
                                 virStorageSourcePtr parent)
 {
-    unsigned int access_user = src->drv->uid;
-    unsigned int access_group = src->drv->gid;
 
-    if (src == parent) {
-        virReportSystemError(errcode,
-                             _("Cannot access storage file '%s' "
-                               "(as uid:%u, gid:%u)"),
-                             src->path, access_user, access_group);
+    if (src->drv) {
+        unsigned int access_user = src->drv->uid;
+        unsigned int access_group = src->drv->gid;
+
+        if (src == parent) {
+            virReportSystemError(errcode,
+                                 _("Cannot access storage file '%s' "
+                                   "(as uid:%u, gid:%u)"),
+                                 src->path, access_user, access_group);
+        } else {
+            virReportSystemError(errcode,
+                                 _("Cannot access backing file '%s' "
+                                   "of storage file '%s' (as uid:%u, gid:%u)"),
+                                 src->path, parent->path, access_user, access_group);
+        }
     } else {
-        virReportSystemError(errcode,
-                             _("Cannot access backing file '%s' "
-                               "of storage file '%s' (as uid:%u, gid:%u)"),
-                             src->path, parent->path, access_user, access_group);
+        if (src == parent) {
+            virReportSystemError(errcode,
+                                 _("Cannot access storage file '%s'"),
+                                 src->path);
+        } else {
+            virReportSystemError(errcode,
+                                 _("Cannot access backing file '%s' "
+                                   "of storage file '%s'"),
+                                 src->path, parent->path);
+        }
     }
 }
 
-- 
2.15.1