]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uuid: use boost::random:random_device 9741/head
authorSage Weil <sage@redhat.com>
Mon, 24 Aug 2015 18:51:47 +0000 (14:51 -0400)
committerNathan Cutler <ncutler@suse.com>
Thu, 16 Jun 2016 06:53:52 +0000 (08:53 +0200)
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>
(cherry picked from commit dbcaa544856fcc99ab912a101c4a28e1eb3fb94e)

Conflicts:
ceph.spec.in (trivial resolution)

ceph.spec.in
configure.ac
debian/control
src/common/Makefile.am
src/include/uuid.h

index 600afc50676c8ab292ae99c6e81ff081013f59fa..6e06a18c36778f334749daebc25dc3b88899a524 100644 (file)
@@ -50,6 +50,7 @@ BuildRequires: sharutils
 %endif
 BuildRequires: gcc-c++
 BuildRequires: boost-devel
+BuildRequires:  boost-random
 %if 0%{defined suse_version}
 BuildRequires:  libbz2-devel
 %else
index 2fa729bcda1d3c300e4a0c0f83e279f9b3b2a748..cf3cb209de098b4eb55d079014fc96e0cf867777 100644 (file)
@@ -882,6 +882,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 c16db0f550ddbdc0be1eae743fec49a187d339d5..bce749bbc9c9929681ad863dbae4032621fb2ce0 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 8fa29899c10f9debc8755950e6dce4c3b71a13da..ed37ceffb29e1e37188f36e806a01c3c3b98c5e6 100644 (file)
@@ -134,7 +134,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
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();
   }