Mailing List Archive

bug in lib/getcwd.pl
As I discovered today when my home directory was moved to
/disk/pertsserver/0/hull/, &getcwd fails on a directory that has a
file named "0" because of sloppy truth testing. "if ($x)" is *not*
the same as "if ($x ne '')". I wonder how many other perl programs
suffer from the same kind of problem?

My problem was with Perl 4, version 36, but I found that the bug still
exists in Perl 5. The following changes fix this bug:

*** /local/encap/perl-4.036/lib/getcwd.pl Tue May 4 15:58:24 1993
--- getcwd.pl Mon Sep 11 12:02:30 1995
***************
*** 36,42 ****
{
do
{
! unless ($dir = readdir(getcwd'PARENT)) #'))
{
warn "readdir($dotdots): $!";
closedir(getcwd'PARENT); #');
--- 36,42 ----
{
do
{
! unless (($dir = readdir(getcwd'PARENT)) ne "") #'))
{
warn "readdir($dotdots): $!";
closedir(getcwd'PARENT); #');
***************
*** 54,60 ****
}
$cwd = "$dir/$cwd";
closedir(getcwd'PARENT); #');
! } while ($dir);
chop($cwd);
$cwd;
}
--- 54,60 ----
}
$cwd = "$dir/$cwd";
closedir(getcwd'PARENT); #');
! } while ($dir ne "");
chop($cwd);
$cwd;
}

-David Hull