bin/find-can-be-private-symbols.functions.results |    1 +
 desktop/source/lib/init.cxx                       |   22 +++++++++++++++++++++-
 sal/osl/unx/random.cxx                            |    8 +++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)

New commits:
commit 75973267b0cf8661a815574eeb80e43eb3b9c8fc
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Fri Apr 5 14:56:13 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Apr 6 22:07:49 2024 +0200

    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 <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/bin/find-can-be-private-symbols.functions.results 
b/bin/find-can-be-private-symbols.functions.results
index 02cd245cbb54..075c73e10125 100644
--- a/bin/find-can-be-private-symbols.functions.results
+++ b/bin/find-can-be-private-symbols.functions.results
@@ -20152,6 +20152,7 @@ linguistic::SpellAlternatives::SetFailureType(short)
 linguistic::SpellAlternatives::SetWordLanguage(rtl::OUString const&, 
o3tl::strong_int<unsigned short, LanguageTypeTag>)
 linguistic::SpellAlternatives::SpellAlternatives()
 load_BLAS
+lok_open_urandom
 longdual_testset
 lower_utf(w_char, int)
 lp_solve_version
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 2c4fba114092..1c047116a22d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -33,8 +33,10 @@
 
 #undef HAVE_MALLOC_TRIM
 
+#ifdef UNX
+#  include <fcntl.h>
+#endif
 #ifdef LINUX
-#include <fcntl.h>
 #if defined __GLIBC__
 #  include <malloc.h>
 #  define HAVE_MALLOC_TRIM
@@ -249,6 +251,20 @@ using namespace bridge;
 using namespace uno;
 using namespace lang;
 
+#ifdef UNX
+
+static int urandom = -1;
+
+extern "C" {
+    int SAL_JNI_EXPORT lok_open_urandom()
+    {
+        return dup(urandom);
+    }
+};
+
+#endif
+
+
 using LanguageToolCfg = 
officecfg::Office::Linguistic::GrammarChecking::LanguageTool;
 
 static LibLibreOffice_Impl *gImpl = nullptr;
@@ -7944,6 +7960,10 @@ static int lo_initialize(LibreOfficeKit* pThis, const 
char* pAppPath, const char
         const char* tz = ::getenv("TZ");
         SfxLokHelper::setDefaultTimezone(!!tz, tz ? OStringToOUString(tz, 
RTL_TEXTENCODING_UTF8)
                                                   : OUString());
+#ifdef UNX
+        if (urandom < 0)
+            urandom = open("/dev/urandom", O_RDONLY);
+#endif
     }
 
     if (eStage != SECOND_INIT)
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)

Reply via email to