[libvirt] [PATCH] tests: avoid seclabeltest crash

Eric Blake eblake at redhat.com
Fri Jul 20 20:46:54 UTC 2012


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




More information about the libvir-list mailing list