]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uuid: use boost::random:random_device 5650/head
authorSage Weil <sage@redhat.com>
Mon, 24 Aug 2015 18:51:47 +0000 (14:51 -0400)
committerSage Weil <sage@redhat.com>
Mon, 24 Aug 2015 18:51:47 +0000 (14:51 -0400)
The boost mt code uses uninitialized memory for extra randomness,
which is a bad idea in general but more importantly makes valgrind
unhappy.  Use /dev/urandom instead.

Unfortunately this introduces a link time dependency.. meh!

Fixes: #12736
Signed-off-by: Sage Weil <sage@redhat.com>
ceph.spec.in
configure.ac
debian/control
src/common/Makefile.am
src/include/uuid.h

index 9d85f76008bbee421b8cf74f0f01c1acd4266b8b..e8a4999e1b684172fafc5a74217c063e394abd43 100644 (file)
@@ -88,6 +88,7 @@ BuildRequires:        /usr/share/selinux/devel/policyhelp
 %endif
 BuildRequires: gcc-c++
 BuildRequires: boost-devel
+BuildRequires:  boost-random
 BuildRequires: cryptsetup
 BuildRequires: gdbm
 BuildRequires: hdparm
index b6a686d98bb24f1ec105070a43be188ef0949881..7447d3d98b29599fc3f883c2d0bed9ee9c1c05b7 100644 (file)
@@ -915,6 +915,17 @@ BOOST_THREAD_LIBS="${LIBS}"
 LIBS="${saved_LIBS}"
 AC_SUBST(BOOST_THREAD_LIBS)
 
+# boost-random
+BOOST_RANDOM_LIBS=""
+saved_LIBS="${LIBS}"
+LIBS=""
+AC_CHECK_LIB(boost_random, main, [],
+    [AC_CHECK_LIB(boost_random, main, [],
+        AC_MSG_FAILURE(["Boost random library not found."]))])
+BOOST_RANDOM_LIBS="${LIBS}"
+LIBS="${saved_LIBS}"
+AC_SUBST(BOOST_RANDOM_LIBS)
+
 #
 # Check for boost_program_options library (defines BOOST_PROGRAM_OPTIONS_LIBS).
 #
index a11b44b91845351e1d8d04134f27e9a90e913f9a..d4d6eb6412f6e67c13fa164651a1db4ee45bddb2 100644 (file)
@@ -27,6 +27,7 @@ Build-Depends: autoconf,
                libboost-program-options-dev (>= 1.42),
                libboost-system-dev (>= 1.42),
                libboost-thread-dev (>= 1.42),
+              libboost-random-dev,
                libcurl4-gnutls-dev,
                libedit-dev,
                libexpat1-dev,
index a474c8ba5b367be55e1767faa74e2596657eb939..a9b57d64d8c5c0c1c528f333c838d4311f86b979 100644 (file)
@@ -132,7 +132,8 @@ noinst_HEADERS += \
 LIBCOMMON_DEPS += \
        $(LIBERASURE_CODE) \
        $(LIBMSG) $(LIBAUTH) \
-       $(LIBCRUSH) $(LIBJSON_SPIRIT) $(LIBLOG) $(LIBARCH)
+       $(LIBCRUSH) $(LIBJSON_SPIRIT) $(LIBLOG) $(LIBARCH) \
+       $(BOOST_RANDOM_LIBS)
 
 if LINUX
 LIBCOMMON_DEPS += -lrt -lblkid
index df9e71a466224ca31d6060817322f6a7d4a653b1..03e6b5ad32c798402a4375d584ebb41890f629fd 100644 (file)
@@ -11,6 +11,7 @@
 #include <boost/uuid/uuid.hpp>
 #include <boost/uuid/uuid_generators.hpp>
 #include <boost/uuid/uuid_io.hpp>
+#include <boost/random/random_device.hpp>
 
 struct uuid_d {
   boost::uuids::uuid uuid;
@@ -25,7 +26,8 @@ struct uuid_d {
   }
 
   void generate_random() {
-    boost::uuids::random_generator gen;
+    boost::random::random_device rng("/dev/urandom");
+    boost::uuids::basic_random_generator<boost::random::random_device> gen(&rng);
     uuid = gen();
   }