summaryrefslogtreecommitdiffstats
path: root/bin/pax/pax.c
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2001-04-26 07:32:27 +0000
committerkris <kris@FreeBSD.org>2001-04-26 07:32:27 +0000
commitb4108a06977f82330a90556ab13b966e612c07bd (patch)
tree603ac0713480106dd78aca671b84a5a062353694 /bin/pax/pax.c
parent580e2df3fd9942f9758180515afe99d21010c590 (diff)
downloadFreeBSD-src-b4108a06977f82330a90556ab13b966e612c07bd.zip
FreeBSD-src-b4108a06977f82330a90556ab13b966e612c07bd.tar.gz
Use mkstemp() for secure tempfile creation instead of tempnam()
Obtained from: OpenBSD Reviewed by: mikeh
Diffstat (limited to 'bin/pax/pax.c')
-rw-r--r--bin/pax/pax.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/pax/pax.c b/bin/pax/pax.c
index 641d53f..5eb57ea 100644
--- a/bin/pax/pax.c
+++ b/bin/pax/pax.c
@@ -55,6 +55,7 @@ static const char rcsid[] =
#include <sys/resource.h>
#include <errno.h>
#include <locale.h>
+#include <paths.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -96,6 +97,8 @@ int exit_val; /* exit value */
int docrc; /* check/create file crc */
char *dirptr; /* destination dir in a copy */
char *argv0; /* root of argv[0] */
+char *tempfile; /* tempfile to use for mkstemp(3) */
+char *tempbase; /* basename of tempfile to use for mkstemp(3) */
sigset_t s_mask; /* signal mask for cleanup critical sect */
/*
@@ -228,7 +231,29 @@ main(argc, argv)
char **argv;
#endif
{
+ char *tmpdir;
+ size_t tdlen;
+
(void) setlocale(LC_ALL, "");
+
+ /*
+ * Where should we put temporary files?
+ */
+ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
+ tmpdir = _PATH_TMP;
+ tdlen = strlen(tmpdir);
+ while(tdlen > 0 && tmpdir[tdlen - 1] == '/')
+ tdlen--;
+ tempfile = malloc(tdlen + 1 + sizeof(_TFILE_BASE));
+ if (tempfile == NULL) {
+ pax_warn(1, "Cannot allocate memory for temp file name.");
+ return(exit_val);
+ }
+ if (tdlen)
+ memcpy(tempfile, tmpdir, tdlen);
+ tempbase = tempfile + tdlen;
+ *tempbase++ = '/';
+
/*
* parse options, determine operational mode, general init
*/
OpenPOWER on IntegriCloud