Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zmq::seed_random() is never called #4633

Open
axelriet opened this issue Nov 29, 2023 · 0 comments
Open

zmq::seed_random() is never called #4633

axelriet opened this issue Nov 29, 2023 · 0 comments

Comments

@axelriet
Copy link
Contributor

axelriet commented Nov 29, 2023

zmq::generate_random() is called from many places but zmq::seed_random() is never called, meaning zmq::generate_random() calls an unseeded rand() and probably generates the same pseudo-random sequence every time. This may have an impact for example on the ws:// protocol. Moreover, using now() + pid is a poor seed (if zmq::seed_random() is ever called) - should use rand_s() as seed in zmq::seed_random(), or empty zmq::seed_random() and only use rand_s() in zmq::generate_random()

rand_s() incidentally returns an uint32_t which would avoid the current gymnastics consisting in calling rand() twice. Also the mere existence of zmq::seed_random()/zmq::generate_random() could be construed as an attempt to get better numbers than rand() - otherwise why not just call rand()? - therefore the second option, no-op zmq::seed_random() and use rand_s() in zmq::generate_random() makes sense.

On platforms where rand_s isn't available, maybe use libsodium if configured, at least for the seed, and make sure zmq::seed_random() is called once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant