From b1298dff5420990a14333bae952f27461982b8e4 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 16 May 2019 15:03:40 +0100 Subject: [PATCH] Fix use of getrandom() for Linux and WITH_TLS=no. --- ChangeLog.txt | 4 ++++ lib/util_mosq.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9dbc0e3d..c6f9525e 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -5,6 +5,10 @@ Broker: - Fix detection of incoming v3.1/v3.1.1 bridges. Closes #1263. - Fix default max_topic_alias listener config not being copied to the in-use listener when compiled without TLS support. +- Fix random number generation if compiling using WITH_TLS=no and on Linux + with glibc >= 2.25. Without this fix, no random numbers would be generated + for e.g. on broker client id generation, and so clients connecting expecting + this feature would be unable to connect. Clients: - Fix -L url parsing when `/topic` part is missing. diff --git a/lib/util_mosq.c b/lib/util_mosq.c index 8f3610a8..7c0b6724 100644 --- a/lib/util_mosq.c +++ b/lib/util_mosq.c @@ -326,7 +326,7 @@ int util__random_bytes(void *bytes, int count) rc = MOSQ_ERR_SUCCESS; } #elif defined(__GLIBC__) && __GLIBC_PREREQ(2, 25) - if(getrandom(bytes, count, 0) == 0){ + if(getrandom(bytes, count, 0) == count){ rc = MOSQ_ERR_SUCCESS; } #elif defined(WIN32)