summaryrefslogtreecommitdiff
path: root/perlio.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-06-10 22:42:15 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2009-06-10 22:44:54 +0200
commit0b99e9860ee94a7d55fe93fe492e8286fdfa409d (patch)
tree5ac72afd8b37d48b90470c54d9f04c309d3422b5 /perlio.c
parent92a24ac3df5779ed0c9681cafefdd31fc6e1ae98 (diff)
downloadperl-0b99e9860ee94a7d55fe93fe492e8286fdfa409d.tar.gz
Do not honor TMPDIR for anonymous temporary files when tainting
Use a default of /tmp on Unixes when TMPDIR is unset or empty, or when creation of a temporary file in it fails This goes on top of commit 26e8050aaf2eeca2f04cdc7bc5df07f8dc4ff0f9
Diffstat (limited to 'perlio.c')
-rw-r--r--perlio.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/perlio.c b/perlio.c
index 89718e9889..10a32c163e 100644
--- a/perlio.c
+++ b/perlio.c
@@ -5174,20 +5174,30 @@ PerlIO_tmpfile(void)
f = PerlIO_fdopen(fd, "w+b");
#else /* WIN32 */
# if defined(HAS_MKSTEMP) && ! defined(VMS) && ! defined(OS2)
- const char * const tmpdir = PerlEnv_getenv("TMPDIR");
- SV * const sv = newSVpv(tmpdir ? tmpdir : "/tmp", 0);
- sv_catpv(sv, "/PerlIO_XXXXXX");
+ int fd = -1;
+ char tempname[] = "/tmp/PerlIO_XXXXXX";
+ const char * const tmpdir = PL_tainting ? NULL : PerlEnv_getenv("TMPDIR");
+ SV * const sv = tmpdir && *tmpdir ? newSVpv(tmpdir, 0) : NULL;
/*
* I have no idea how portable mkstemp() is ... NI-S
*/
- const int fd = mkstemp(SvPVX(sv));
+ if (sv) {
+ /* if TMPDIR is set and not empty, we try that first */
+ sv_catpv(sv, tempname + 4);
+ fd = mkstemp(SvPVX(sv));
+ }
+ if (fd < 0) {
+ /* else we try /tmp */
+ fd = mkstemp(tempname);
+ }
if (fd >= 0) {
f = PerlIO_fdopen(fd, "w+");
if (f)
PerlIOBase(f)->flags |= PERLIO_F_TEMP;
- PerlLIO_unlink(SvPVX_const(sv));
+ PerlLIO_unlink(sv ? SvPVX_const(sv) : tempname);
}
- SvREFCNT_dec(sv);
+ if (sv)
+ SvREFCNT_dec(sv);
# else /* !HAS_MKSTEMP, fallback to stdio tmpfile(). */
FILE * const stdio = PerlSIO_tmpfile();