-
Notifications
You must be signed in to change notification settings - Fork 581
File::Spec::Unix->tmpdir: Always return an absolute path #13434
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
Comments
From @HugmeirCreated by @HugmeirThis is generally a non-issue, however, if /tmp doesn't exist use File::Temp qw(tempdir); Because $tmpdir would be something like 'bfhskjf94589', and after (note that the patch doesn't up the version of Cwd and friends) --- Inline Patchdiff --git a/dist/Cwd/lib/File/Spec/Unix.pm b/dist/Cwd/lib/File/Spec/Unix.pm
index 868b6a7..7030994 100644
--- a/dist/Cwd/lib/File/Spec/Unix.pm
+++ b/dist/Cwd/lib/File/Spec/Unix.pm
@@ -193,6 +193,9 @@ sub _tmpdir {
}
$tmpdir = $self->curdir unless defined $tmpdir;
$tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
+ if ( $tmpdir eq '.' ) {
+ $tmpdir = defined $tmpdir && $self->rel2abs($tmpdir);
+ }
return $tmpdir;
}
diff --git a/dist/Cwd/t/tmpdir.t b/dist/Cwd/t/tmpdir.t
index 7c13da1..0f03dc5 100644
--- a/dist/Cwd/t/tmpdir.t
+++ b/dist/Cwd/t/tmpdir.t
@@ -1,5 +1,5 @@
use strict;
-use Test::More tests => 7;
+use Test::More tests => 8;
# Grab all of the plain routines from File::Spec
use File::Spec;
@@ -46,3 +46,8 @@ for ('File::Spec', "File::Spec::Win32") {
isn't $tmpdir2, $tmpdir1, "$_->tmpdir works with changing env";
}
}
+
+ok(
+ File::Spec->file_name_is_absolute(File::Spec->tmpdir()),
+ "tmpdir() always returns an absolute path"
+);
-- Perl Info
|
From @Hugmeir0001-File-Spec-Unix-tmpdir-Always-return-an-absolute-path.patchFrom 990718d5423f1b1caaad6d20c6c80c624836e659 Mon Sep 17 00:00:00 2001
From: Brian Fraser <[email protected]>
Date: Sun, 19 May 2013 04:39:04 -0300
Subject: [PATCH 1/9] File::Spec::Unix->tmpdir: Always return an absolute path
This is generally a non-issue, however, if /tmp doesn't exist
and $ENV{TMPDIR} isn't set, ->tmpdir() used to return ".", which
broke the following pattern:
use File::Temp qw(tempdir);
use File::Spec;
my $tmpdir = tempdir(CLEANUP => 1);
chdir $tmpdir;
my $file = File::Spec->catfile($tmpdir, "foo");
open my $fh, ">", $file or die $!;
Because $tmpdir would be something like 'bfhskjf94589', and after
the chdir, the open() would've tried to open $tmpdir/$tmpdir/foo.
---
dist/Cwd/lib/File/Spec/Unix.pm | 3 +++
dist/Cwd/t/tmpdir.t | 7 ++++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/dist/Cwd/lib/File/Spec/Unix.pm b/dist/Cwd/lib/File/Spec/Unix.pm
index 868b6a7..7030994 100644
--- a/dist/Cwd/lib/File/Spec/Unix.pm
+++ b/dist/Cwd/lib/File/Spec/Unix.pm
@@ -193,6 +193,9 @@ sub _tmpdir {
}
$tmpdir = $self->curdir unless defined $tmpdir;
$tmpdir = defined $tmpdir && $self->canonpath($tmpdir);
+ if ( $tmpdir eq '.' ) {
+ $tmpdir = defined $tmpdir && $self->rel2abs($tmpdir);
+ }
return $tmpdir;
}
diff --git a/dist/Cwd/t/tmpdir.t b/dist/Cwd/t/tmpdir.t
index 7c13da1..0f03dc5 100644
--- a/dist/Cwd/t/tmpdir.t
+++ b/dist/Cwd/t/tmpdir.t
@@ -1,5 +1,5 @@
use strict;
-use Test::More tests => 7;
+use Test::More tests => 8;
# Grab all of the plain routines from File::Spec
use File::Spec;
@@ -46,3 +46,8 @@ for ('File::Spec', "File::Spec::Win32") {
isn't $tmpdir2, $tmpdir1, "$_->tmpdir works with changing env";
}
}
+
+ok(
+ File::Spec->file_name_is_absolute(File::Spec->tmpdir()),
+ "tmpdir() always returns an absolute path"
+);
--
1.8.3.2
|
From @LeontOn Wed, Nov 20, 2013 at 5:15 AM, Brian Fraser <perlbug-followup@perl.org>wrote:
if ( $tmpdir eq '.' ), $tmpdir would surely also be defined ;-) Leon |
The RT System itself - Status changed from 'new' to 'open' |
From @HugmeirOn Wed, Nov 20, 2013 at 1:20 AM, Leon Timmermans <fawaka@gmail.com> wrote:
Whoops, that's what copypaste will get you. Thanks! I'll commit the fixed |
From @epaI understand the idea to make tmpdir return an absolute path, no matter However, are you sure that this won't introduce more problems than it my $tempdir = tempdir; There is plenty of code like this in the wild, using the single-argument open($fh, "cat $tempdir/out |"); If you can get $tempdir to contain shell metacharacters then you can, This is already an issue if the TMPDIR environment variable can be set So I worry that the following exploit becomes possible: % mkdir '; perl -E "0 while 1";' Admittedly, this works only when /tmp does not exist, but that is not I freely admit that the code embedding $tempdir in a string and running I suggest that if /tmp doesn't exist, and TMPDIR is not set, then the And if this is all too apocalyptic for you, just think of the lesser case -- |
From [email protected]I thought File::Spec upstream is on CPAN 2013/11/20 Brian Fraser <perlbug-followup@perl.org>
|
From @timjOn Thu, Nov 21, 2013 at 7:43 AM, Ed Avis <eda@waniasset.com> wrote:
File::Temp has already gone through these shenanigans of turning the The main problem was that Cwd isn't allowed to work when taint is enabled File::Temp->tmpdir already refuses to return a tainted value if taint is -- |
From @HugmeirOn Thu, Nov 21, 2013 at 11:43 AM, Ed Avis <eda@waniasset.com> wrote:
->tmpdir would return a tainted value for this case, actually;
I disagree. File::Spec is not the place for validations, and it strikes me
I have no qualms with breaking buggy code. This would be easy enough to |
From @HugmeirOn Thu, Nov 21, 2013 at 12:28 PM, Tim Jenness <tim.jenness@gmail.com> wrote:
This I don't understand. What part of Cwd doesn't work under taint?
From a quick test, File::Temp->newdir() and tempdir() both work under taint |
From @timjOn Sat, Nov 23, 2013 at 1:00 PM, Brian Fraser <fraserbn@gmail.com> wrote:
The cwd directory itself is tainted.
Yes. In taint mode you don't get the absolute path. If you are running
The full path is tainted when you concat cwd with the temp file name. Then -- |
From @epaReturning a tainted tmpdir() mitigates the problem somewhat, as long as code runs with taint checks enabled. ______________________________________________________________________ |
From @timjOn Sun, Nov 24, 2013 at 12:25 AM, Ed Avis <eda@waniasset.com> wrote:
File::Spec already ignores environment variables in taint mode. tmpdir() -- |
From @jkeenanOn Sat Nov 23 20:46:09 2013, tim.jenness@gmail.com wrote:
Tim, Is the thrust of your argument that this feature request ought to be rejected? Thank you very much. |
From @timjOn Tue, Dec 10, 2013 at 5:19 PM, James E Keenan via RT <
All I was noting was to think about taint mode and that Cwd can't be used I don't really have an opinion on whether tmpdir should return an absolute -- |
From @HugmeirOn Tue, Dec 10, 2013 at 11:48 PM, Tim Jenness <tim.jenness@gmail.com> wrote:
So what should it return under taint mode? Having it return '.' means that
As much as it panders to my laziness, I don't think we can just say that |
From @timjOn Wed, Dec 11, 2013 at 4:17 PM, Brian Fraser <fraserbn@gmail.com> wrote:
How are you getting the untainted cwd? In this case the default /tmp is Our choices without a taint-free Cwd are to 1. Return "." The problem being that with 2 as soon as you use it in a sys call you get
I'm not saying it's fixed in taint mode. If it was possible for CWD to -- |
From @HugmeirOn Wed, Dec 11, 2013 at 8:23 PM, Tim Jenness <tim.jenness@gmail.com> wrote:
Hm. Looks like there will be no perfect solution then. How about making a |
From @timjOn Wed, Dec 11, 2013 at 5:01 PM, Brian Fraser <fraserbn@gmail.com> wrote:
That's what we did in File::Temp. Nice reliable absolute paths if we are -- |
Migrated from rt.perl.org#120593 (status was 'open')
Searchable as RT120593$
The text was updated successfully, but these errors were encountered: