]> xenbits.xensource.com Git - libvirt.git/commitdiff
Fix building domain def in securityselinuxtest
authorJim Fehlig <jfehlig@suse.com>
Wed, 16 Aug 2017 21:45:54 +0000 (15:45 -0600)
committerJim Fehlig <jfehlig@suse.com>
Mon, 21 Aug 2017 15:10:31 +0000 (09:10 -0600)
The virDomainDef created by testBuildDomainDef in securityselinuxtest
adds a seclabel but does not increment nseclabels. Also, it should
populate seclabel->model with 'selinux'.

While at it, use the secdef itself to populate values instead of
the indirection through def->seclabels[0].

tests/securityselinuxtest.c

index 767b6cc026a013baaf65ad8c7888ff5aa25ed6e2..f6bc07a84640b5ee320fdba9f5c2ac6181974434 100644 (file)
@@ -73,24 +73,27 @@ testBuildDomainDef(bool dynamic,
     if (!(def = virDomainDefNew()))
         goto error;
 
+    def->virtType = VIR_DOMAIN_VIRT_KVM;
     if (VIR_ALLOC_N(def->seclabels, 1) < 0)
         goto error;
 
     if (VIR_ALLOC(secdef) < 0)
         goto error;
 
-    def->virtType = VIR_DOMAIN_VIRT_KVM;
-    def->seclabels[0] = secdef;
-    def->seclabels[0]->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC;
+    if (VIR_STRDUP(secdef->model, "selinux") < 0)
+        goto error;
 
+    secdef->type = dynamic ? VIR_DOMAIN_SECLABEL_DYNAMIC : VIR_DOMAIN_SECLABEL_STATIC;
     if (label &&
-        VIR_STRDUP(def->seclabels[0]->label, label) < 0)
+        VIR_STRDUP(secdef->label, label) < 0)
         goto error;
 
     if (baselabel &&
-        VIR_STRDUP(def->seclabels[0]->baselabel, baselabel) < 0)
+        VIR_STRDUP(secdef->baselabel, baselabel) < 0)
         goto error;
 
+    def->seclabels[0] = secdef;
+    def->nseclabels++;
     return def;
 
  error: