Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
e49a861f
Unverified
Commit
e49a861f
authored
Mar 19, 2018
by
Simon Giesecke
Committed by
GitHub
Mar 19, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3001 from bluca/sodium_global_init
Problem: global random init/deinit breaks existing applications
parents
4d9fc806
8f5fc705
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
6 deletions
+20
-6
random.cpp
src/random.cpp
+20
-6
No files found.
src/random.cpp
View file @
e49a861f
...
...
@@ -86,6 +86,14 @@ uint32_t zmq::generate_random ()
// order fiasco, this is done using function-local statics, if the
// compiler implementation supports thread-safe initialization of those.
// Otherwise, we fall back to global statics.
// HOWEVER, this initialisation code imposes ordering constraints, which
// are not obvious to users of libzmq, and may lead to problems if atexit
// or similar methods are used for cleanup.
// In that case, a strict ordering is imposed whereas the contexts MUST
// be initialised BEFORE registering the cleanup with atexit. CZMQ is an
// example. Hence we make the choice to restrict this global transition
// mechanism ONLY to Tweenacl + *NIX (when using /dev/urandom) as it is
// the less risky option.
// TODO if there is some other user of libsodium besides libzmq, this must
// be synchronized by the application. This should probably also be
...
...
@@ -105,18 +113,16 @@ uint32_t zmq::generate_random ()
#endif
#if !ZMQ_HAVE_THREADSAFE_STATIC_LOCAL_INIT \
&& (defined(ZMQ_USE_LIBSODIUM) \
|| (defined(ZMQ_USE_TWEETNACL) && !defined(ZMQ_HAVE_WINDOWS) \
&& !defined(ZMQ_HAVE_GETRANDOM)))
&& (defined(ZMQ_USE_TWEETNACL) && !defined(ZMQ_HAVE_WINDOWS) \
&& !defined(ZMQ_HAVE_GETRANDOM))
static
unsigned
int
random_refcount
=
0
;
static
zmq
::
mutex_t
random_sync
;
#endif
static
void
manage_random
(
bool
init
)
{
#if defined(ZMQ_USE_LIBSODIUM) \
|| (defined(ZMQ_USE_TWEETNACL) && !defined(ZMQ_HAVE_WINDOWS) \
&& !defined(ZMQ_HAVE_GETRANDOM))
#if defined(ZMQ_USE_TWEETNACL) && !defined(ZMQ_HAVE_WINDOWS) \
&& !defined(ZMQ_HAVE_GETRANDOM)
#if ZMQ_HAVE_THREADSAFE_STATIC_LOCAL_INIT
static
int
random_refcount
=
0
;
...
...
@@ -140,6 +146,14 @@ static void manage_random (bool init)
randombytes_close
();
}
}
#elif defined(ZMQ_USE_LIBSODIUM)
if
(
init
)
{
int
rc
=
sodium_init
();
zmq_assert
(
rc
!=
-
1
);
}
else
{
randombytes_close
();
}
#endif
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment