Skip to content

Commit

Permalink
add TMP/TEMP/TEMPDIR to the TMPDIR DropPrivileges dance
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DonKult committed Nov 11, 2016
1 parent 5860894 commit e2c8c82
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions apt-pkg/contrib/fileutl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2778,9 +2778,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)
Expand All @@ -2796,6 +2796,11 @@ std::string GetTempDir() /*{{{*/
tmpdir = "/tmp";

return string(tmpdir);
}
/*}}}*/
std::string GetTempDir() /*{{{*/
{
return GetTempDirEnv("TMPDIR");
}
std::string GetTempDir(std::string const &User)
{
Expand Down Expand Up @@ -3062,13 +3067,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;
Expand Down

0 comments on commit e2c8c82

Please sign in to comment.