From 187d308b5b0cb0512b442bbad1bddfda8ef9203f Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 24 Aug 2015 14:51:47 -0400 Subject: [PATCH] uuid: use boost::random:random_device 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 (cherry picked from commit dbcaa544856fcc99ab912a101c4a28e1eb3fb94e) Conflicts: ceph.spec.in (trivial resolution) --- ceph.spec.in | 1 + configure.ac | 11 +++++++++++ debian/control | 1 + src/common/Makefile.am | 3 ++- src/include/uuid.h | 4 +++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ceph.spec.in b/ceph.spec.in index 600afc50676..6e06a18c367 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -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 diff --git a/configure.ac b/configure.ac index 2fa729bcda1..cf3cb209de0 100644 --- a/configure.ac +++ b/configure.ac @@ -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). # diff --git a/debian/control b/debian/control index c16db0f550d..bce749bbc9c 100644 --- a/debian/control +++ b/debian/control @@ -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, diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 8fa29899c10..ed37ceffb29 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 diff --git a/src/include/uuid.h b/src/include/uuid.h index df9e71a4662..03e6b5ad32c 100644 --- a/src/include/uuid.h +++ b/src/include/uuid.h @@ -11,6 +11,7 @@ #include #include #include +#include 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 gen(&rng); uuid = gen(); } -- 2.47.3