c401cc
From e294159bef2aa05b9c9de22ece4d7b8893fb68c9 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <e294159bef2aa05b9c9de22ece4d7b8893fb68c9@dist-git>
c401cc
From: Eric Blake <eblake@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:37 +0100
c401cc
Subject: [PATCH] storage: skip selinux cleanup when fd not available
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
When attempting to backport gluster pools to an older versoin
c401cc
where there is no VIR_STRDUP, I got a crash from calling
c401cc
strdup(,NULL). Rather than relying on the current else branch
c401cc
safely doing nothing when there is no fd, it is easier to just
c401cc
skip it. While at it, there's no need to explicitly set
c401cc
perms.label to NULL after a VIR_FREE().
c401cc
c401cc
* src/storage/storage_backend.c
c401cc
(virStorageBackendUpdateVolTargetInfoFD): Minor optimization.
c401cc
c401cc
Signed-off-by: Eric Blake <eblake@redhat.com>
c401cc
(cherry picked from commit c8b8b50c3bcf46ebe5f3a152ff681779024a0846)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/storage/storage_backend.c | 26 ++++++++++++--------------
c401cc
 1 file changed, 12 insertions(+), 14 deletions(-)
c401cc
c401cc
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
c401cc
index ae24c74..982cf43 100644
c401cc
--- a/src/storage/storage_backend.c
c401cc
+++ b/src/storage/storage_backend.c
c401cc
@@ -1356,24 +1356,22 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
c401cc
 
c401cc
 #if WITH_SELINUX
c401cc
     /* XXX: make this a security driver call */
c401cc
-    if (fd >= 0 && fgetfilecon_raw(fd, &filecon) == -1) {
c401cc
-        if (errno != ENODATA && errno != ENOTSUP) {
c401cc
-            virReportSystemError(errno,
c401cc
-                                 _("cannot get file context of '%s'"),
c401cc
-                                 target->path);
c401cc
-            return -1;
c401cc
+    if (fd >= 0) {
c401cc
+        if (fgetfilecon_raw(fd, &filecon) == -1) {
c401cc
+            if (errno != ENODATA && errno != ENOTSUP) {
c401cc
+                virReportSystemError(errno,
c401cc
+                                     _("cannot get file context of '%s'"),
c401cc
+                                     target->path);
c401cc
+                return -1;
c401cc
+            }
c401cc
         } else {
c401cc
-            target->perms.label = NULL;
c401cc
-        }
c401cc
-    } else {
c401cc
-        if (VIR_STRDUP(target->perms.label, filecon) < 0) {
c401cc
+            if (VIR_STRDUP(target->perms.label, filecon) < 0) {
c401cc
+                freecon(filecon);
c401cc
+                return -1;
c401cc
+            }
c401cc
             freecon(filecon);
c401cc
-            return -1;
c401cc
         }
c401cc
-        freecon(filecon);
c401cc
     }
c401cc
-#else
c401cc
-    target->perms.label = NULL;
c401cc
 #endif
c401cc
 
c401cc
     return 0;
c401cc
-- 
c401cc
1.9.0
c401cc