summaryrefslogtreecommitdiff
path: root/cmdline/apt-extracttemplates.cc
diff options
context:
space:
mode:
authorMichael Vogt <mvo@debian.org>2014-03-27 10:14:30 +0100
committerMichael Vogt <mvo@debian.org>2014-03-27 10:14:30 +0100
commit8d50b63f28f0d68ca72b6dc6e50e09cfec9842be (patch)
tree07459f54a6fc1a24745fcfa769a7b6b0ea58b086 /cmdline/apt-extracttemplates.cc
parent12c4e7c92a8909130ce9af17ef68d7383b57b1f6 (diff)
Use mkstemp() in apt-extracttemplaes (closes: #741627)
Use mkstemp() in apt-extractemplates and add a integrationtest for apt-extracttemplates too. Thanks to Steve Kemp for the report.
Diffstat (limited to 'cmdline/apt-extracttemplates.cc')
-rw-r--r--cmdline/apt-extracttemplates.cc15
1 files changed, 9 insertions, 6 deletions
diff --git a/cmdline/apt-extracttemplates.cc b/cmdline/apt-extracttemplates.cc
index a82623444..e4428e051 100644
--- a/cmdline/apt-extracttemplates.cc
+++ b/cmdline/apt-extracttemplates.cc
@@ -37,6 +37,7 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <stdlib.h>
#include "apt-extracttemplates.h"
@@ -239,23 +240,25 @@ static int ShowHelp(void)
static string WriteFile(const char *package, const char *prefix, const char *data)
{
char fn[512];
- static int i;
std::string tempdir = GetTempDir();
- snprintf(fn, sizeof(fn), "%s/%s.%s.%u%d",
+ snprintf(fn, sizeof(fn), "%s/%s.%s.XXXXXX",
_config->Find("APT::ExtractTemplates::TempDir",
tempdir.c_str()).c_str(),
- package, prefix, getpid(), i++);
+ package, prefix);
FileFd f;
if (data == NULL)
data = "";
-
- if (!f.Open(fn, FileFd::WriteTemp, 0600))
+ int fd = mkstemp(fn);
+ if (fd < 0) {
+ _error->Errno("ofstream::ofstream",_("Unable to mkstemp %s"),fn);
+ return string();
+ }
+ if (!f.OpenDescriptor(fd, FileFd::WriteOnly, FileFd::None, true))
{
_error->Errno("ofstream::ofstream",_("Unable to write to %s"),fn);
return string();
}
-
f.Write(data, strlen(data));
f.Close();
return fn;