[EMAIL PROTECTED] (via RT) wrote:
> Say we have a script /opt/test.pl who use FindBin::Bin.
> Say that the user foo has read and execute access to the /opt directory.
> Say that the user foo has no access to the /home/bar directory.
> 
> When I run, as bar, and into the /home/bar directory:
> "sudo -u foo /opt/test.pl",
> the $FindBin::Bin is empty, instead to be equal to "/opt/".

The problem actually comes from Cwd, because getcwd() doesn't find the
current directory if it has no access to it. cwd() does.

The patch below might fix this, modulo portability problems :

Change 24375 by [EMAIL PROTECTED] on 2005/05/03 08:53:25

        Fix for [perl #34252] Access rights in FindBin::Bin
        At least on my platform, Cwd::getcwd doesn't find the current
        directory if it has no access to it. Try harder with Cwd::cwd.

Affected files ...

... //depot/perl/lib/FindBin.pm#18 edit

Differences ...

==== //depot/perl/lib/FindBin.pm#18 (text) ====

@@ -93,7 +93,7 @@
 use Carp;
 require 5.000;
 require Exporter;
-use Cwd qw(getcwd abs_path);
+use Cwd qw(getcwd cwd abs_path);
 use Config;
 use File::Basename;
 use File::Spec;
@@ -102,7 +102,7 @@
 %EXPORT_TAGS = (ALL => [qw($Bin $Script $RealBin $RealScript $Dir $RealDir)]);
 @ISA = qw(Exporter);
 
-$VERSION = "1.44";
+$VERSION = "1.45";
 
 sub init
 {
@@ -158,8 +158,10 @@
 
      croak("Cannot find current script '$0'") unless(-f $script);
 
-     # Ensure $script contains the complete path incase we C<chdir>
+     # Ensure $script contains the complete path in case we C<chdir>
 
+     my $cwd = getcwd();
+     defined $cwd or $cwd = cwd(); # try harder
      $script = File::Spec->catfile(getcwd(), $script)
        unless File::Spec->file_name_is_absolute($script);
 

Reply via email to