New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TMPDIR not honored when opening an anonymous temporary file #9764
Comments
From @ntyniThis is a bug report for perl from Niko Tyni <ntyni@debian.org>, In <http://bugs.debian.org/528544>, Norbert Buchmuller <norbi@nix.hu> I'm attaching a patch against current blead based on his original one. I'm uneasy on failing when TMPDIR is set but doesn't exist or isn't Also, should we worry about tainting issues? Flags: Site configuration information for perl 5.11.0: Configured by niko at Sat May 30 21:54:25 EEST 2009. Summary of my perl5 (revision 5 version 11 subversion 0) configuration: Locally applied patches: @INC for perl 5.11.0: Environment for perl 5.11.0: |
From @ntyni0001-Honor-TMPDIR-when-open-ing-an-anonymous-temporary-f.patchFrom e97df03b198389a9fe2eb71def8423a0bfbf6df8 Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Tue, 9 Jun 2009 22:56:32 +0300
Subject: [PATCH] Honor TMPDIR when open()ing an anonymous temporary file
As reported in <http://bugs.debian.org/528544>, opening an anonymous
temporary file with the magical open($fh, '+>', undef) currently ignores
TMPDIR.
Original patch by Norbert Buchmuller <norbi@nix.hu>.
---
perlio.c | 4 +++-
t/io/perlio.t | 15 ++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/perlio.c b/perlio.c
index e92a32a..89718e9 100644
--- a/perlio.c
+++ b/perlio.c
@@ -5174,7 +5174,9 @@ PerlIO_tmpfile(void)
f = PerlIO_fdopen(fd, "w+b");
#else /* WIN32 */
# if defined(HAS_MKSTEMP) && ! defined(VMS) && ! defined(OS2)
- SV * const sv = newSVpvs("/tmp/PerlIO_XXXXXX");
+ const char * const tmpdir = PerlEnv_getenv("TMPDIR");
+ SV * const sv = newSVpv(tmpdir ? tmpdir : "/tmp", 0);
+ sv_catpv(sv, "/PerlIO_XXXXXX");
/*
* I have no idea how portable mkstemp() is ... NI-S
*/
diff --git a/t/io/perlio.t b/t/io/perlio.t
index c145945..8d76d91 100644
--- a/t/io/perlio.t
+++ b/t/io/perlio.t
@@ -8,13 +8,14 @@ BEGIN {
}
}
-use Test::More tests => 37;
+use Test::More tests => 39;
use_ok('PerlIO');
my $txt = "txt$$";
my $bin = "bin$$";
my $utf = "utf$$";
+my $nonexistent = "nex$$";
my $txtfh;
my $binfh;
@@ -89,6 +90,17 @@ ok(close($utffh));
# report after STDOUT is restored
ok($status, ' re-open STDOUT');
close OLDOUT;
+
+ SKIP: {
+ skip("TMPDIR not honored on this platform", 2)
+ if !$Config{d_mkstemp}
+ || $^O eq 'VMS' || $^O eq 'MSwin32' || $^O eq 'os2';
+ local $ENV{TMPDIR} = $nonexistent;
+ ok( !open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - fails if TMPDIR points to a non-existent dir');
+
+ mkdir $ENV{TMPDIR};
+ ok(open(my $x,"+<",undef), 'TMPDIR honored by magic temp file via 3 arg open with undef - works if TMPDIR points to an existent dir');
+ }
}
# in-memory open
@@ -136,5 +148,6 @@ END {
1 while unlink $txt;
1 while unlink $bin;
1 while unlink $utf;
+ 1 while rmdir $nonexistent;
}
--
1.5.6.5
|
From @smpetersOn Tue Jun 09 13:41:58 2009, ntyni@debian.org wrote:
I've applied the patch as change 26e8050, but I'm leaving it open while I work on the Steve Peters |
The RT System itself - Status changed from 'new' to 'open' |
From @rgs2009/6/9 Niko Tyni <perlbug-followup@perl.org>:
I see that the patch was already applied, but your concern is worthwhile. However, stat'ing the TMPDIR is not enough. There is a race condition. Also, I would completely disable reading TMPDIR if tainted. |
From @rgs2009/6/10 Rafael Garcia-Suarez <rgarciasuarez@gmail.com>:
All of this is implemented now by : commit 0b99e98 Do not honor TMPDIR for anonymous temporary files when tainting Use a default of /tmp on Unixes when TMPDIR is unset or empty, or This goes on top of commit 26e8050 |
From @jkeenanOn Wed Jun 10 13:53:38 2009, rafael wrote:
My reading of Rafael's comment suggests that this ticket should have Thank you very much. |
From @jkeenanOn Sun Feb 24 14:46:51 2013, jkeenan wrote:
Closing as per schedule. |
@jkeenan - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#66452 (status was 'resolved')
Searchable as RT66452$
The text was updated successfully, but these errors were encountered: