[PATCH] tests: avoid seclabeltest crash

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

 



Commit a56c347 introduced a use of random numbers into seclabel
handling, but failed to initialize the random number generator
in the testsuite.

* tests/seclabeltest.c (main): Initialize randomness.
---

Pushing under the build-breaker rule to avoid a SIGSEGV.  I don't
know if Dan's pending patches for one-shot initializer cleanups
will be impacted or make this harder to forget in the future.

 tests/seclabeltest.c |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tests/seclabeltest.c b/tests/seclabeltest.c
index 2f65ec1..7283ca1 100644
--- a/tests/seclabeltest.c
+++ b/tests/seclabeltest.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <errno.h>
 #include "security/security_driver.h"
+#include "virrandom.h"

 int
 main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
@@ -13,10 +14,14 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     virSecurityManagerPtr mgr;
     const char *doi, *model;

+    if (virThreadInitialize() < 0 ||
+        virRandomInitialize(time(NULL) ^ getpid()))
+        exit(1);
+
     mgr = virSecurityManagerNew(NULL, "QEMU", false, true, false);
     if (mgr == NULL) {
         fprintf (stderr, "Failed to start security driver");
-        exit (-1);
+        exit(1);
     }

     model = virSecurityManagerGetModel(mgr);
@@ -24,7 +29,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf (stderr, "Failed to copy secModel model: %s",
                  strerror (errno));
-        exit (-1);
+        exit(1);
     }

     doi = virSecurityManagerGetDOI(mgr);
@@ -32,7 +37,7 @@ main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
     {
         fprintf (stderr, "Failed to copy secModel DOI: %s",
                  strerror (errno));
-        exit (-1);
+        exit(1);
     }

     virSecurityManagerFree(mgr);
-- 
1.7.10.4

--
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]