summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-11-11 09:18:49 +0100
committerJulian Andres Klode <jak@debian.org>2017-02-22 18:11:43 +0100
commit5262898c5449b38f0243c6381e15a17687cff337 (patch)
tree5561ca9b7ac357bdc755bbfc4e532928fdb06ac5 /apt-pkg
parentba6c85665c06a8151f13469811365b71842b5fc4 (diff)
add TMP/TEMP/TEMPDIR to the TMPDIR DropPrivileges dance
apt tools do not really support these other variables, but tools apt calls might, so lets play save and clean those up as needed. Reported-By: Paul Wise (pabs) on IRC (cherry picked from commit e2c8c825a5470e33c25d00e07de188d0e03922c8) (cherry picked from commit 52067bd0a9e23642b7fa791fb63f4b69cafceb36)
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/contrib/fileutl.cc29
1 files changed, 20 insertions, 9 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index e18fa7cf3..1691c8ad4 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -2719,9 +2719,9 @@ std::vector<std::string> Glob(std::string const &pattern, int flags)
return result;
}
/*}}}*/
-std::string GetTempDir() /*{{{*/
+static std::string APT_NONNULL(1) GetTempDirEnv(char const * const env) /*{{{*/
{
- const char *tmpdir = getenv("TMPDIR");
+ const char *tmpdir = getenv(env);
#ifdef P_tmpdir
if (!tmpdir)
@@ -2738,6 +2738,11 @@ std::string GetTempDir() /*{{{*/
return string(tmpdir);
}
+ /*}}}*/
+std::string GetTempDir() /*{{{*/
+{
+ return GetTempDirEnv("TMPDIR");
+}
std::string GetTempDir(std::string const &User)
{
// no need/possibility to drop privs
@@ -3003,13 +3008,19 @@ bool DropPrivileges() /*{{{*/
setenv("SHELL", "/bin/sh", 1);
else
setenv("SHELL", pw->pw_shell, 1);
- auto const tmpdir = getenv("TMPDIR");
- if (tmpdir != nullptr)
- {
- auto const ourtmpdir = GetTempDir();
- if (ourtmpdir != tmpdir)
- setenv("TMPDIR", ourtmpdir.c_str(), 1);
- }
+ auto const apt_setenv_tmp = [](char const * const env) {
+ auto const tmpdir = getenv(env);
+ if (tmpdir != nullptr)
+ {
+ auto const ourtmpdir = GetTempDirEnv(env);
+ if (ourtmpdir != tmpdir)
+ setenv(env, ourtmpdir.c_str(), 1);
+ }
+ };
+ apt_setenv_tmp("TMPDIR");
+ apt_setenv_tmp("TEMPDIR");
+ apt_setenv_tmp("TMP");
+ apt_setenv_tmp("TEMP");
}
return true;