common/Util.cpp | 24 ++++++++++++++++++++++++ common/Util.hpp | 3 +++ kit/Kit.cpp | 5 +++++ 3 files changed, 32 insertions(+)
New commits: commit 6803ee4087ea8358f4985416810cab05e6153b47 Author: Michael Meeks <michael.me...@collabora.com> Date: Wed Mar 14 15:46:52 2018 +0000 Use a hard random /tmp directory for document intermediates. Requires a lok tweak to reset the tmpdir globals on init. Change-Id: I602705f20fa016ef415088be8d1ada6d465d2a8d diff --git a/common/Util.cpp b/common/Util.cpp index 7f320d382..37edd665f 100644 --- a/common/Util.cpp +++ b/common/Util.cpp @@ -116,6 +116,30 @@ namespace Util } } + static std::string getDefaultTmpDir() + { + const char *tmp = getenv("TMPDIR"); + if (!tmp) + tmp = getenv("TEMP"); + if (!tmp) + tmp = getenv("TMP"); + if (!tmp) + tmp = "/tmp"; + return tmp; + } + + std::string createRandomTmpDir() + { + std::string defaultTmp = getDefaultTmpDir(); + std::string newTmp = + defaultTmp + "/lool-" + rng::getFilename(16); + if (::mkdir(newTmp.c_str(), S_IRWXU) < 0) { + LOG_ERR("Failed to create random temp directory"); + return defaultTmp; + } + return newTmp; + } + // close what we have - far faster than going up to a 1m open_max eg. static bool closeFdsFromProc() { diff --git a/common/Util.hpp b/common/Util.hpp index d6864589f..6bbcd3d03 100644 --- a/common/Util.hpp +++ b/common/Util.hpp @@ -45,6 +45,9 @@ namespace Util std::string getFilename(const size_t length); } + /// Create randomized temporary directory + std::string createRandomTmpDir(); + /// Spawn a process if stdInput is non-NULL it contains a writable descriptor /// to send data to the child. int spawnProcess(const std::string &cmd, const std::vector<std::string> &args, diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 9868224d1..89f045ad9 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -1989,6 +1989,7 @@ void lokit_main(const std::string& childRoot, } Util::rng::reseed(); + const std::string LogLevel = logLevel ? logLevel : "trace"; const bool bTraceStartup = (std::getenv("LOOL_TRACE_STARTUP") != nullptr); Log::initialize("kit", bTraceStartup ? "trace" : logLevel, logColor != nullptr, logToFile, logProperties); @@ -2123,6 +2124,10 @@ void lokit_main(const std::string& childRoot, instdir_path = "/" + loTemplate + "/program"; } + // hard-random tmpdir inside the jail / root + std::string tmpSubdir = Util::createRandomTmpDir(); + ::setenv("TMPDIR", tmpSubdir.c_str(), 1); + { const char *instdir = instdir_path.c_str(); const char *userdir = userdir_url.c_str(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits