summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2024-04-05 14:56:13 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-04-06 22:07:49 +0200
commit75973267b0cf8661a815574eeb80e43eb3b9c8fc (patch)
tree485cca3792493bc796b0ed40e2b5af839dbdb0ce /sal
parentfd7bd64ce930724ff5a60414b94a3c122f29d2aa (diff)
lok: provide global random symbol to find random device.
This is vital for lok when used in a jail with no random device, but with an inherited file-handle to /dev/urandom. Use 'dup' to avoid changing code that wants to 'close' the handle after use. Change-Id: I15f40fb251f180a2394af030f56e47f2bf9651d4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165850 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/unx/random.cxx8
1 files changed, 7 insertions, 1 deletions
diff --git a/sal/osl/unx/random.cxx b/sal/osl/unx/random.cxx
index e8379f8f0bf7..62a552ce4ea3 100644
--- a/sal/osl/unx/random.cxx
+++ b/sal/osl/unx/random.cxx
@@ -13,13 +13,19 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
+#include <dlfcn.h>
int osl_get_system_random_data(char* buffer, size_t desired_len)
{
int fd;
assert(buffer);
- fd = open("/dev/urandom", O_RDONLY);
+
+ static int (*lok_open_urandom)()
+ = reinterpret_cast<int (*)()>(dlsym(RTLD_DEFAULT, "lok_open_urandom"));
+ if (!lok_open_urandom || (fd = lok_open_urandom()) < 0)
+ fd = open("/dev/urandom", O_RDONLY);
+
if (fd != -1)
{
while (desired_len)