[PATCH v2 22/37] Adapt to VIR_STRDUP in src/security/*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/security/security_apparmor.c | 11 ++++-----
 src/security/security_dac.c      |  6 ++---
 src/security/security_nop.c      |  4 ++--
 src/security/security_selinux.c  | 49 ++++++++++++++++------------------------
 src/security/virt-aa-helper.c    |  4 ++--
 5 files changed, 30 insertions(+), 44 deletions(-)

diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index a2deafb..e75886e 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -446,21 +446,18 @@ AppArmorGenSecurityLabel(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
     if ((profile_name = get_profile_name(def)) == NULL)
         return rc;
 
-    secdef->label = strndup(profile_name, strlen(profile_name));
-    if (!secdef->label) {
+    if (VIR_STRNDUP(secdef->label, profile_name, strlen(profile_name)) < 0) {
         virReportOOMError();
         goto clean;
     }
 
     /* set imagelabel the same as label (but we won't use it) */
-    secdef->imagelabel = strndup(profile_name,
-                                 strlen(profile_name));
-    if (!secdef->imagelabel) {
+    if (VIR_STRNDUP(secdef->imagelabel, profile_name, strlen(profile_name)) < 0) {
         virReportOOMError();
         goto err;
     }
 
-    if (!secdef->model && !(secdef->model = strdup(SECURITY_APPARMOR_NAME))) {
+    if (!secdef->model && VIR_STRDUP(secdef->model, SECURITY_APPARMOR_NAME) < 0) {
         virReportOOMError();
         goto err;
     }
@@ -931,7 +928,7 @@ AppArmorGetMountOptions(virSecurityManagerPtr mgr ATTRIBUTE_UNUSED,
 {
     char *opts;
 
-    if (!(opts = strdup(""))) {
+    if (VIR_STRDUP(opts, "") < 0) {
         virReportOOMError();
         return NULL;
     }
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 4143495..850b9d4 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -76,8 +76,7 @@ int parseIds(const char *label, uid_t *uidPtr, gid_t *gidPtr)
     char *owner = NULL;
     char *group = NULL;
 
-    tmp_label = strdup(label);
-    if (tmp_label == NULL) {
+    if (VIR_STRDUP(tmp_label, label) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1051,8 +1050,7 @@ virSecurityDACGenLabel(virSecurityManagerPtr mgr,
 
     if (!seclabel->norelabel) {
         if (seclabel->imagelabel == NULL && seclabel->label != NULL) {
-            seclabel->imagelabel = strdup(seclabel->label);
-            if (seclabel->imagelabel == NULL) {
+            if (VIR_STRDUP(seclabel->imagelabel, seclabel->label) < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("cannot generate dac user and group id "
                                  "for domain %s"), def->name);
diff --git a/src/security/security_nop.c b/src/security/security_nop.c
index 2b9767e..00f4d67 100644
--- a/src/security/security_nop.c
+++ b/src/security/security_nop.c
@@ -20,7 +20,7 @@
 #include <config.h>
 
 #include "security_nop.h"
-
+#include "virstring.h"
 #include "virerror.h"
 
 #define VIR_FROM_THIS VIR_FROM_SECURITY
@@ -182,7 +182,7 @@ static char *virSecurityDomainGetMountOptionsNop(virSecurityManagerPtr mgr ATTRI
 {
     char *opts;
 
-    if (!(opts = strdup(""))) {
+    if (VIR_STRDUP(opts, "") < 0) {
         virReportOOMError();
         return NULL;
     }
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 201fff6..13f0601 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -202,7 +202,7 @@ virSecuritySELinuxMCSGetProcessRange(char **sens,
         goto cleanup;
     }
 
-    if (!(*sens = strdup(context_range_get(ourContext)))) {
+    if (VIR_STRDUP(*sens, context_range_get(ourContext)) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -312,7 +312,7 @@ virSecuritySELinuxContextAddRange(security_context_t src,
         goto cleanup;
     }
 
-    if (!(ret = strdup(str))) {
+    if (VIR_STRDUP(ret, str) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -385,7 +385,7 @@ virSecuritySELinuxGenNewContext(const char *basecontext,
                              _("Unable to format SELinux context"));
         goto cleanup;
     }
-    if (!(ret = strdup(str))) {
+    if (VIR_STRDUP(ret, str) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -451,12 +451,9 @@ virSecuritySELinuxLXCInitialize(virSecurityManagerPtr mgr)
         goto error;
     }
 
-    data->domain_context = strdup(scon->str);
-    data->file_context = strdup(tcon->str);
-    data->content_context = strdup(dcon->str);
-    if (!data->domain_context ||
-        !data->file_context ||
-        !data->content_context) {
+    if (VIR_STRDUP(data->domain_context, scon->str) < 0 ||
+        VIR_STRDUP(data->file_context, tcon->str) < 0 ||
+        VIR_STRDUP(data->content_context, dcon->str) < 0) {
         virReportSystemError(errno,
                              _("cannot allocate memory for LXC SELinux contexts '%s'"),
                              selinux_lxc_contexts_path());
@@ -520,8 +517,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
         *ptr = '\0';
         ptr++;
         if (*ptr != '\0') {
-            data->alt_domain_context = strdup(ptr);
-            if (!data->alt_domain_context) {
+            if (VIR_STRDUP(data->alt_domain_context, ptr) < 0) {
                 virReportOOMError();
                 goto error;
             }
@@ -544,8 +540,7 @@ virSecuritySELinuxQEMUInitialize(virSecurityManagerPtr mgr)
     ptr = strchrnul(data->file_context, '\n');
     if (ptr && *ptr == '\n') {
         *ptr = '\0';
-        data->content_context = strdup(ptr+1);
-        if (!data->content_context) {
+        if (VIR_STRDUP(data->content_context, ptr+1) < 0) {
             virReportOOMError();
             goto error;
         }
@@ -643,8 +638,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
         }
 
         range = context_range_get(ctx);
-        if (!range ||
-            !(mcs = strdup(range))) {
+        if (!range || VIR_STRDUP(mcs, range) < 0) {
             virReportOOMError();
             goto cleanup;
         }
@@ -710,8 +704,7 @@ virSecuritySELinuxGenSecurityLabel(virSecurityManagerPtr mgr,
             goto cleanup;
     }
 
-    if (!seclabel->model &&
-        !(seclabel->model = strdup(SECURITY_SELINUX_NAME))) {
+    if (!seclabel->model && VIR_STRDUP(seclabel->model, SECURITY_SELINUX_NAME) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1390,7 +1383,7 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def,
                 return -1;
             }
         } else {
-            if (!(path = strdup(dev->source.caps.u.storage.block))) {
+            if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -1408,7 +1401,7 @@ virSecuritySELinuxSetSecurityHostdevCapsLabel(virDomainDefPtr def,
                 return -1;
             }
         } else {
-            if (!(path = strdup(dev->source.caps.u.misc.chardev))) {
+            if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -1557,7 +1550,7 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr,
                 return -1;
             }
         } else {
-            if (!(path = strdup(dev->source.caps.u.storage.block))) {
+            if (VIR_STRDUP(path, dev->source.caps.u.storage.block) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -1575,7 +1568,7 @@ virSecuritySELinuxRestoreSecurityHostdevCapsLabel(virSecurityManagerPtr mgr,
                 return -1;
             }
         } else {
-            if (!(path = strdup(dev->source.caps.u.misc.chardev))) {
+            if (VIR_STRDUP(path, dev->source.caps.u.misc.chardev) < 0) {
                 virReportOOMError();
                 return -1;
             }
@@ -2364,7 +2357,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr,
     const char *range;
     context_t ctx = NULL;
     char *label = NULL;
-    const char *mcs = NULL;
+    char *mcs = NULL;
 
     secdef = virDomainDefGetSecurityLabelDef(def, SECURITY_SELINUX_NAME);
     if (secdef == NULL)
@@ -2378,8 +2371,7 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr,
         }
         range = context_range_get(ctx);
         if (range) {
-            mcs = strdup(range);
-            if (!mcs) {
+            if (VIR_STRDUP(mcs, range) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
@@ -2390,9 +2382,9 @@ virSecuritySELinuxGenImageLabel(virSecurityManagerPtr mgr,
     }
 
 cleanup:
-        context_free(ctx);
-        VIR_FREE(mcs);
-        return label;
+    context_free(ctx);
+    VIR_FREE(mcs);
+    return label;
 }
 
 static char *
@@ -2415,8 +2407,7 @@ virSecuritySELinuxGetSecurityMountOptions(virSecurityManagerPtr mgr,
         }
     }
 
-    if (!opts &&
-        !(opts = strdup(""))) {
+    if (!opts && VIR_STRDUP(opts, "") < 0) {
         virReportOOMError();
         return NULL;
     }
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index b526919..7ead3d0 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -773,7 +773,7 @@ vah_add_file(virBufferPtr buf, const char *path, const char *perms)
             return rc;
         }
     } else
-        if ((tmp = strdup(path)) == NULL)
+        if (VIR_STRDUP(tmp, path) < 0)
             return rc;
 
     if (strchr(perms, 'w') != NULL)
@@ -1103,7 +1103,7 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
                 break;
             case 'f':
             case 'F':
-                if ((ctl->newfile = strdup(optarg)) == NULL)
+                if (VIR_STRDUP(ctl->newfile, optarg) < 0)
                     vah_error(ctl, 1, _("could not allocate memory for disk"));
                 ctl->append = arg == 'F';
                 break;
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]