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/+/166113
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
This commit is contained in:
Michael Meeks
2024-04-15 15:28:41 +02:00
committed by Miklos Vajna
parent 10fa63a773
commit b99082e4f3
3 changed files with 29 additions and 2 deletions
@@ -13449,6 +13449,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
+21 -1
View File
@@ -31,8 +31,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
@@ -234,6 +236,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;
@@ -7903,6 +7919,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)
+7 -1
View File
@@ -13,13 +13,19 @@
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <dlfcn.h>
bool 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)