diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-06-10 22:42:15 +0200 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2009-06-10 22:44:54 +0200 |
commit | 0b99e9860ee94a7d55fe93fe492e8286fdfa409d (patch) | |
tree | 5ac72afd8b37d48b90470c54d9f04c309d3422b5 /perlio.c | |
parent | 92a24ac3df5779ed0c9681cafefdd31fc6e1ae98 (diff) | |
download | perl-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.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -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(); |