From dbcaa544856fcc99ab912a101c4a28e1eb3fb94e 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 --- 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 9d85f76008bbe..e8a4999e1b684 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -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 diff --git a/configure.ac b/configure.ac index b6a686d98bb24..7447d3d98b295 100644 --- a/configure.ac +++ b/configure.ac @@ -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). # diff --git a/debian/control b/debian/control index a11b44b918453..d4d6eb6412f6e 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 a474c8ba5b367..a9b57d64d8c5c 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 diff --git a/src/include/uuid.h b/src/include/uuid.h index df9e71a466224..03e6b5ad32c79 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.39.5