develooper Front page | perl.perl5.porters | Postings from December 2008

[perl #59662] Cwd::realpath fails on unsearchable directory (AIX)

From:
Steve Peters via RT
Date:
December 2, 2008 05:33
Subject:
[perl #59662] Cwd::realpath fails on unsearchable directory (AIX)
Message ID:
rt-3.6.HEAD-10965-1228193906-465.59662-15-0@perl.org
On Mon Oct 06 13:18:14 2008, John.Wiersba@thomsonreuters.com wrote:
> This is a bug report for perl from john.wiersba@thomsonreuters.com,
> generated with the help of perlbug 1.34 running under perl v5.8.2.
>  
> 
> -----------------------------------------------------------------
> [Please enter your report here]
>  
> 1) Compile the following program as ./a.out:
>  
> /* C program to demonstrate that system-supplied realpath() works. */
> #include <stdio.h>
> #include <stdlib.h>
> int main ( void )
> {
>    char buf[1000+1];
>    realpath("testdir", buf);
>    printf("<%s>\n", buf);
> }
>  
> 2) Run the following script:
>  
> #!/bin/ksh
> mkdir testdir
> chmod 444 testdir
> echo "from perl:"
> perl -we '
>    use strict;
>    use Cwd ();
>    print "<", Cwd::realpath("testdir"), ">\n";
> '
> echo "from a.out:"
> ./a.out
> rmdir testdir
>  
> 3) See the following output:
>  
> from perl:
> Use of uninitialized value in print at -e line 4.
> <>
> from a.out:
> </home/jrw32982/junk/testdir>
>  
> 4) Analysis:
>  
> Perl's realpath() is aliased to abs_path() which is aliased to
> _perl_abs_path().  When _perl_abs_path(ARG) sees that ARG is a
> directory, it
> tries to opendir("ARG/..") which fails because ARG is not searchable.
> The
> system-supplied realpath() does not try to opendir("ARG/..") and does
> not
> fail.
>  

This seems to be fixed in recent Cwd's...

riker:perl-current tanya$ mkdir tempdir
riker:perl-current tanya$ chmod 444 tempdir
riker:perl-current tanya$ ./perl -Ilib -MCwd -Mstrict -wle'print "<", Cwd::realpath("testdir
"), ">"'
</Users/tanya/perl-current/testdir>


I'd suggest upgrading to a recent Cwd from CPAN.

Steve Peters



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About