Skip to content
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

FindBin fails if all directories in cwd are not readable #909

Closed
p5pRT opened this issue Dec 1, 1999 · 13 comments
Closed

FindBin fails if all directories in cwd are not readable #909

p5pRT opened this issue Dec 1, 1999 · 13 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Dec 1, 1999

Migrated from rt.perl.org#1844 (status was 'resolved')

Searchable as RT1844$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 1, 1999

From mneme@io.com

Possible solutions​:
  Fix Cwd​::abs_path(), so it doesn't do that. Possibly, rather
than warning and returning, it should use fast_abs_path() instead,
which should handle warnings if they need to be given.
  Alternatively, have FindBin use a fallback if abs_path()
fails.

 

--
  Joshua Kronengold (mneme@​io.com) |\ _,,,--,,_ ,)
---^---- /,`.-'`' -, ;-;;'
  /\\ "What part of "Prhrhrrrrrrrrrrrrrrrrrr" |,4- ) )-,_ ) /\
-/-\\\-- didn't you understand?" '---''(_/--' (_/-'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

From @schwern

[mneme@​io.com - Wed Dec 01 06​:23​:20 1999]​:

Possible solutions​:
Fix Cwd​::abs_path(), so it doesn't do that. Possibly, rather
than warning and returning, it should use fast_abs_path() instead,
which should handle warnings if they need to be given.
Alternatively, have FindBin use a fallback if abs_path()
fails.

I am unable to replicate this behavior on OS X using 5.4.5 or 5.5.4. As
the implementation of Cwd​::abs_path() changes on different operating
systems I cannot be sure this bug does not still exist.

Can you tell us what operating system you were using, and version of
Perl? Can you also try this out on a newer version of Perl?

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

The RT System itself - Status changed from 'stalled' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

@schwern - Status changed from 'open' to 'stalled'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

From @rgarcia

On 7/13/05, Michael G Schwern via RT <perlbug-followup@​perl.org> wrote​:

[mneme@​io.com - Wed Dec 01 06​:23​:20 1999]​:

Possible solutions​:
Fix Cwd​::abs_path(), so it doesn't do that. Possibly, rather
than warning and returning, it should use fast_abs_path() instead,
which should handle warnings if they need to be given.
Alternatively, have FindBin use a fallback if abs_path()
fails.

IIUC that was probably fixed by change #24375 or by further changes.

I am unable to replicate this behavior on OS X using 5.4.5 or 5.5.4. As
the implementation of Cwd​::abs_path() changes on different operating
systems I cannot be sure this bug does not still exist.

Can you tell us what operating system you were using, and version of
Perl? Can you also try this out on a newer version of Perl?

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

The RT System itself - Status changed from 'stalled' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

From mneme@io.com

Rafael Garcia-Suarez via RT writes​:

On 7/13/05, Michael G Schwern via RT <perlbug-followup@​perl.org> wrote​:

[mneme@​io.com - Wed Dec 01 06​:23​:20 1999]​:
Possible solutions​:
Fix Cwd​::abs_path(), so it doesn't do that. Possibly, rather
IIUC that was probably fixed by change #24375 or by further changes.

Seems to have been. I can't replicate it on FreeBSD 4.11/perl 5.8.6
or Linux (FC3) 2.6.11 / perl 5.8.5.

OTOH, I -was- able to replicate it on Solaris (SunOS 5.8) with perl
5.6.2 (work is very conservative in terms of perl versions) (stock
FindBin).

The test program was​:

========================================
#!/usr/bin/perl

use FindBin;

print "Hi there. I am at​: $FindBin​::Bin\n";

When running inside an unreadable directory, it worked fine.

When running inside a directory whose -parent- was unreadable, I got​:

opendir(./..)​: Permission denied at
/usr/local/lib/perl5/5.6.2/FindBin.pm line 143
Hi there. I am at​: /

FWIW, FindBin.pm​:143 is​:
  $script = File​::Spec->catfile(getcwd(), $script)
  unless File​::Spec->file_name_is_absolute($script);

--
  Joshua Kronengold (mneme@​(io.com, labcats.org)) |\ _,,,--,,_ ,)
--^-- "Remember the Doom Team code!" says Tom. /,`.-'`' -, ;-;;'
/\\ "You don't have to die just because some |,4- ) )-,_ ) /\
/-\\\ people think your existence is evil!" '---''(_/--' (_/-'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 13, 2005

From @schwern

On Wed, Jul 13, 2005 at 09​:58​:44AM -0500, Joshua Kronengold wrote​:

OTOH, I -was- able to replicate it on Solaris (SunOS 5.8) with perl
5.6.2 (work is very conservative in terms of perl versions) (stock
FindBin).

The test program was​:

========================================
#!/usr/bin/perl

use FindBin;

print "Hi there. I am at​: $FindBin​::Bin\n";

When running inside an unreadable directory, it worked fine.

When running inside a directory whose -parent- was unreadable, I got​:

opendir(./..)​: Permission denied at
/usr/local/lib/perl5/5.6.2/FindBin.pm line 143
Hi there. I am at​: /

FWIW, FindBin.pm​:143 is​:
$script = File​::Spec->catfile(getcwd(), $script)
unless File​::Spec->file_name_is_absolute($script);

I can replicate on OS X with several versions of perl.

0 ~/tmp/foo/bar$ ls ~/tmp/foo
ls​: /Users/schwern/tmp/foo​: Permission denied

0 ~/tmp/foo/bar$ bleadperl -MFindBin -wle 'print "$FindBin​::Bin"'
pwd​: : Permission denied

0 ~/tmp/foo/bar$ perl5.4.5 -MFindBin -wle 'print "$FindBin​::Bin"'
opendir(./..)​: Permission denied at /usr/local/perl/5.4.5/lib/FindBin.pm line 116

0 ~/tmp/foo/bar$ perl5.5.4 -MFindBin -wle 'print "$FindBin​::Bin"'
opendir(./..)​: Permission denied at /usr/local/perl/5.5.4/lib/5.00504/FindBin.pm line 97

0 ~/tmp/foo/bar$ perl5.8.6 -MFindBin -wle 'print "$FindBin​::Bin"'
Use of uninitialized value in string at -e line 1.

0 ~/tmp/foo/bar$ perl5.8.1 -MFindBin -wle 'print "$FindBin​::Bin"'
Use of uninitialized value in string at -e line 1.

The bleadperl version tries both getcwd() and cwd(). Both fail.
In fact, nothing works​:

$ perl -MCwd -wle 'for (@​ARGV) { print eval "Cwd​::$_()" }' cwd getcwd fastcwd fastgetcwd abs_path fast_abs_path realpath fast_realpath
pwd​: : Permission denied

Use of uninitialized value in print at -e line 1.

Use of uninitialized value in print at -e line 1.

pwd​: : Permission denied

Use of uninitialized value in print at -e line 1.

Use of uninitialized value in pattern match (m//) at /sw/lib/perl5-core/5.8.6/darwin-thread-multi-2level/Cwd.pm line 566.

Use of uninitialized value in print at -e line 1.

Use of uninitialized value in pattern match (m//) at /sw/lib/perl5-core/5.8.6/darwin-thread-multi-2level/Cwd.pm line 566.

I don't know if this can be fixed as the only reliable method at this
point is $ENV{PWD} which is not guaranteed to have been kept up to date.
CORE​::chdir would have to do that and it doesn't. Sure would be nice if
it did though.

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
Reality is that which, when you stop believing in it, doesn't go away.
  -- Phillip K. Dick

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 14, 2005

From mneme@io.com

On Wed, 13 Jul 2005 7​:17 pm, Michael G Schwern via RT wrote​:

The bleadperl version tries both getcwd() and cwd(). Both fail.
In fact, nothing works​:

I think shelling out usually works (on unixlike systems) as a last
resort.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 14, 2005

From @schwern

On Wed, Jul 13, 2005 at 07​:43​:13PM -0400, Joshua Kronengold wrote​:

On Wed, 13 Jul 2005 7​:17 pm, Michael G Schwern via RT wrote​:

The bleadperl version tries both getcwd() and cwd(). Both fail.
In fact, nothing works​:

I think shelling out usually works (on unixlike systems) as a last
resort.

One of the things Cwd tries is `pwd`. It doesn't work because it doesn't
have any more information to go on than Perl does.

0 ~/tmp/foo/bar$ perl -wle 'print `pwd`'
pwd​: : Permission denied

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
You are wicked and wrong to have broken inside and peeked at the
implementation and then relied upon it.
  -- tchrist in <31832.969261130@​chthon>

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 14, 2005

From mneme@io.com

On Thu, 14 Jul 2005 6​:37 am, Michael G Schwern wrote​:

One of the things Cwd tries is `pwd`. It doesn't work because it
doesn't
have any more information to go on than Perl does.

Wow.
Um -- what are the perms on the directory in question? I'd expect this
behavior for perms set to, say, 000 -- the bug as originally reported
was for directories set to things that pwd normally can deal with, like
001.

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jul 14, 2005

From @schwern

On Thu, Jul 14, 2005 at 07​:11​:41AM -0400, Joshua Kronengold wrote​:

On Thu, 14 Jul 2005 6​:37 am, Michael G Schwern wrote​:

One of the things Cwd tries is `pwd`. It doesn't work because it
doesn't
have any more information to go on than Perl does.

Wow.
Um -- what are the perms on the directory in question? I'd expect this
behavior for perms set to, say, 000 -- the bug as originally reported
was for directories set to things that pwd normally can deal with, like
001.

Oh, I was using an unreadable and unexecutable parent directory.

If I try it with 0711...

0 ~/tmp/foo/bar$ sudo chmod 711 ../../foo
0 ~/tmp/foo/bar$ ls -ld ../../foo
drwx--x--x 6 root wheel 204 Jul 13 16​:02 ../../foo
0 ~/tmp/foo/bar$ whoami
schwern
0 ~/tmp/foo/bar$ groups
schwern staff appserverusr admin appserveradm perl
0 ~/tmp/foo/bar$ bleadperl -MFindBin -wle 'print $FindBin​::Bin'
pwd​: : Permission denied

0 ~/tmp/foo/bar$ perl -MFindBin -wle 'print $FindBin​::Bin'
Use of uninitialized value in print at -e line 1.

0 ~/tmp/foo/bar$ perl -wle 'print `pwd`'
pwd​: : Permission denied

0 ~/tmp/foo/bar$ pwd
/Users/schwern/tmp/foo/bar

That last one works because its the shell's internal pwd using $PWD.

--
Michael G Schwern schwern@​pobox.com http​://www.pobox.com/~schwern
Ahh email, my old friend. Do you know that revenge is a dish that is best
served cold? And it is very cold on the Internet!

@p5pRT p5pRT closed this Nov 20, 2006
@p5pRT
Copy link
Author

@p5pRT p5pRT commented Nov 20, 2006

@rgs - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant