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

File::Find::find dies when an empty directory list is supplied. #15042

Closed
p5pRT opened this issue Nov 10, 2015 · 14 comments
Closed

File::Find::find dies when an empty directory list is supplied. #15042

p5pRT opened this issue Nov 10, 2015 · 14 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 10, 2015

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

Searchable as RT126611$

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

From Mohammed_ElAfifi@yahoo.com

Created by Mohammed_ElAfifi@yahoo.com

File​::Find​::find(and similarly its cousine finddepth) die when an
empty list of directories is provided. So something like this

find sub {};

will die with a message
"invalid top directory at /usr/share/perl5/File/Find.pm line X."

This makes it a little tedious to test an array before passing it
to find, like this​:

find sub {}, @​directories if @​directories;

or worse if more than one array is used, like this​:

find sub {}, @​dirs1, @​dirs2 if @​dirs1 || @​dirs2;

I've created a trivial patch that would return early if the
provided directory array is empty. The patch also contains a
simple test case to illustrate the problem.

The problem is reproducible on different platforms(windows and
linux) and even on the latest blead sources.

Things I'm not sure I did right​:
- I bumped the version of File​::Find to avoid a failure in some
  version comparison test.
- I tried to closely follow the test code style, but don't know
  if it's the best way to test this scenario.

Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl 5.20.3:

Configured by Red Hat, Inc. at Thu Sep 24 08:45:26 UTC 2015.

Summary of my perl5 (revision 5 version 20 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=4.1.6-100.fc21.x86_64, archname=x86_64-linux-thread-multi
    uname='linux buildvm-04.phx2.fedoraproject.org 4.1.6-100.fc21.x86_64 #1 smp mon aug 17 22:20:37 utc 2015 x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic -Wl,-z,relro  -Dshrpdir=/usr/lib64 -DDEBUGGING=-g -Dversion=5.20.3 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5 -Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl -Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl -Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64 /usr/lib64 -Duseshrplib -Dusethreads -Duseithreads -Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dscriptdir=/usr/bin -Dusesitecustomize'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='5.1.1 20150618 (Red Hat 5.1.1-4)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib64 /lib64 /usr/lib64 /usr/local/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib
    libs=-lpthread -lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.21.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.21'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--enable-new-dtags'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wl,-z,relro  -L/usr/local/lib'

Locally applied patches:
    Fedora Patch1: Removes date check, Fedora/RHEL specific
    Fedora Patch3: support for libdir64
    Fedora Patch4: use libresolv instead of libbind
    Fedora Patch5: USE_MM_LD_RUN_PATH
    Fedora Patch6: Skip hostname tests, due to builders not being network capable
    Fedora Patch7: Dont run one io test due to random builder failures
    Fedora Patch15: Define SONAME for libperl.so
    Fedora Patch16: Install libperl.so to -Dshrpdir value
    Fedora Patch22: Document Math::BigInt::CalcEmu requires Math::BigInt (CPAN RT#85015)
    Fedora Patch25: Use stronger algorithm needed for FIPS in t/op/crypt.t (RT#121591)
    Fedora Patch26: Make *DBM_File desctructors thread-safe (RT#61912)
    Fedora Patch27: Report inaccesible file on failed require (RT#123270)
    Fedora Patch28: Use stronger algorithm needed for FIPS in t/op/taint.t (RT#123338)
    Fedora Patch29: Fix debugger y command scope level
    Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux
    Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux


@INC for perl 5.20.3:
    /usr/local/lib64/perl5
    /usr/local/share/perl5
    /usr/lib64/perl5/vendor_perl
    /usr/share/perl5/vendor_perl
    /usr/lib64/perl5
    /usr/share/perl5
    .


Environment for perl 5.20.3:
    HOME=/home/mel-afifi
    LANG=en_US.UTF-8
    LANGUAGE=
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin:/usr/sbin:/home/mel-afifi/.local/bin:/home/mel-afifi/bin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

From Mohammed_ElAfifi@yahoo.com

On Tue Nov 10 12​:03​:03 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

This is a bug report for perl from Mohammed_ElAfifi@​yahoo.com,
generated with the help of perlbug 1.40 running under perl 5.20.3.

-----------------------------------------------------------------
[Please describe your issue here]

File​::Find​::find(and similarly its cousine finddepth) die when an
empty list of directories is provided. So something like this

find sub {};

will die with a message
"invalid top directory at /usr/share/perl5/File/Find.pm line X."

This makes it a little tedious to test an array before passing it
to find, like this​:

find sub {}, @​directories if @​directories;

or worse if more than one array is used, like this​:

find sub {}, @​dirs1, @​dirs2 if @​dirs1 || @​dirs2;

I've created a trivial patch that would return early if the
provided directory array is empty. The patch also contains a
simple test case to illustrate the problem.

The problem is reproducible on different platforms(windows and
linux) and even on the latest blead sources.

Things I'm not sure I did right​:
- I bumped the version of File​::Find to avoid a failure in some
version comparison test.
- I tried to closely follow the test code style, but don't know
if it's the best way to test this scenario.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=library
severity=medium
---
Site configuration information for perl 5.20.3​:

Configured by Red Hat, Inc. at Thu Sep 24 08​:45​:26 UTC 2015.

Summary of my perl5 (revision 5 version 20 subversion 3)
configuration​:

Platform​:
osname=linux, osvers=4.1.6-100.fc21.x86_64, archname=x86_64-linux-
thread-multi
uname='linux buildvm-04.phx2.fedoraproject.org 4.1.6-100.fc21.x86_64
#1 smp mon aug 17 22​:20​:37 utc 2015 x86_64 x86_64 x86_64 gnulinux '
config_args='-des -Doptimize=-O2 -g -pipe -Wall -Werror=format-
security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong
--param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic
-Dccdlflags=-Wl,--enable-new-dtags -Dlddlflags=-shared -O2 -g -pipe
-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-
switches -m64 -mtune=generic -Wl,-z,relro -Dshrpdir=/usr/lib64
-DDEBUGGING=-g -Dversion=5.20.3 -Dmyhostname=localhost
-Dperladmin=root@​localhost -Dcc=gcc -Dcf_by=Red Hat, Inc.
-Dprefix=/usr -Dvendorprefix=/usr -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl5 -Dsitearch=/usr/local/lib64/perl5
-Dprivlib=/usr/share/perl5 -Dvendorlib=/usr/share/perl5/vendor_perl
-Darchlib=/usr/lib64/perl5 -Dvendorarch=/usr/lib64/perl5/vendor_perl
-Darchname=x86_64-linux-thread-multi -Dlibpth=/usr/local/lib64 /lib64
/usr/lib64 -Duseshrplib -Dusethreads -Duseithreads
-Dusedtrace=/usr/bin/dtrace -Duselargefiles -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto
-Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto
-Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto
-Dscriptdir=/usr/bin -Dusesitecustomize'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-
aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2 -g -pipe -Wall -Werror=format-security -Wp,-
D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-
buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic',
cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing
-pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='5.1.1 20150618 (Red Hat 5.1.1-4)',
gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries​:
ld='gcc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib64 /lib64 /usr/lib64 /usr/local/lib /usr/lib
/lib/../lib64 /usr/lib/../lib64 /lib
libs=-lpthread -lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil
-lc -lgdbm_compat
perllibs=-lpthread -lresolv -lnsl -ldl -lm -lcrypt -lutil -lc
libc=libc-2.21.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.21'
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,--
enable-new-dtags'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-
protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64
-mtune=generic -Wl,-z,relro -L/usr/local/lib'

Locally applied patches​:
Fedora Patch1​: Removes date check, Fedora/RHEL specific
Fedora Patch3​: support for libdir64
Fedora Patch4​: use libresolv instead of libbind
Fedora Patch5​: USE_MM_LD_RUN_PATH
Fedora Patch6​: Skip hostname tests, due to builders not being
network capable
Fedora Patch7​: Dont run one io test due to random builder failures
Fedora Patch15​: Define SONAME for libperl.so
Fedora Patch16​: Install libperl.so to -Dshrpdir value
Fedora Patch22​: Document Math​::BigInt​::CalcEmu requires
Math​::BigInt (CPAN RT#85015)
Fedora Patch25​: Use stronger algorithm needed for FIPS in
t/op/crypt.t (RT#121591)
Fedora Patch26​: Make *DBM_File desctructors thread-safe (RT#61912)
Fedora Patch27​: Report inaccesible file on failed require
(RT#123270)
Fedora Patch28​: Use stronger algorithm needed for FIPS in
t/op/taint.t (RT#123338)
Fedora Patch29​: Fix debugger y command scope level
Fedora Patch200​: Link XS modules to libperl.so with EU​::CBuilder
on Linux
Fedora Patch201​: Link XS modules to libperl.so with EU​::MM on
Linux

---
@​INC for perl 5.20.3​:
/usr/local/lib64/perl5
/usr/local/share/perl5
/usr/lib64/perl5/vendor_perl
/usr/share/perl5/vendor_perl
/usr/lib64/perl5
/usr/share/perl5
.

---
Environment for perl 5.20.3​:
HOME=/home/mel-afifi
LANG=en_US.UTF-8
LANGUAGE=
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/bin​:/usr/bin​:/usr/local/bin​:/usr/local/sbin​:/usr/sbin​:/home/mel-
afifi/.local/bin​:/home/mel-afifi/bin
PERL_BADLANG (unset)
SHELL=/bin/bash

Forgot to attach the patches, sorry.

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

From Mohammed_ElAfifi@yahoo.com

0001-add-test-for-empty-directory-list-with-File-Find.patch
From fc1698fb3cb67fe01774b7b83af8ec8460260d59 Mon Sep 17 00:00:00 2001
From: Mohammed El-Afifi <Mohammed_ElAfifi@yahoo.com>
Date: Mon, 9 Nov 2015 23:49:08 +0200
Subject: [PATCH 1/2] add test for empty directory list with File::Find

---
 AUTHORS                |  1 +
 ext/File-Find/t/find.t | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/AUTHORS b/AUTHORS
index ebd9222..d56db73 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1271,3 +1271,4 @@ Zefram				<zefram@fysh.org>
 Zsbán Ambrus			<ambrus@math.bme.hu>
 Zbynek Vyskovsky		<kvr@centrum.cz>
 Ævar Arnfjörð Bjarmason		<avar@cpan.org>
+Mohammed El-Afifi		<mohammed_elafifi@yahoo.com>
diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t
index 390f39d..b04f9d3 100644
--- a/ext/File-Find/t/find.t
+++ b/ext/File-Find/t/find.t
@@ -24,7 +24,7 @@ BEGIN {
 }
 
 my $symlink_exists = eval { symlink("",""); 1 };
-my $test_count = 109;
+my $test_count = 111;
 $test_count += 127 if $symlink_exists;
 $test_count += 26 if $^O eq 'MSWin32';
 $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists;
@@ -66,6 +66,16 @@ my $orig_dir = cwd();
 cleanup();
 
 ##### Sanity checks #####
+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+    find(\&noop_wanted);
+    pass("'find' successfully returned for an empty list of directories");
+
+    finddepth(\&noop_wanted);
+    pass("'finddepth' successfully returned for an empty list of directories");
+}
+
 # Do find() and finddepth() work correctly in the directory
 # from which we start?  (Test presumes the presence of 'taint.t' in same
 # directory as this test file.)
-- 
2.4.3

@p5pRT
Copy link
Author

p5pRT commented Nov 10, 2015

From Mohammed_ElAfifi@yahoo.com

0002-fix-File-Find-to-handle-empty-directory-list.patch
From e4b57cf5a4a2fecdfd61ebe814ae3f9998641dc1 Mon Sep 17 00:00:00 2001
From: Mohammed El-Afifi <Mohammed_ElAfifi@yahoo.com>
Date: Tue, 10 Nov 2015 00:36:12 +0200
Subject: [PATCH 2/2] fix File::Find to handle empty directory list

---
 ext/File-Find/lib/File/Find.pm | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ext/File-Find/lib/File/Find.pm b/ext/File-Find/lib/File/Find.pm
index 094d5ea..36242d4 100644
--- a/ext/File-Find/lib/File/Find.pm
+++ b/ext/File-Find/lib/File/Find.pm
@@ -3,7 +3,7 @@ use 5.006;
 use strict;
 use warnings;
 use warnings::register;
-our $VERSION = '1.31';
+our $VERSION = '1.32';
 require Exporter;
 require Cwd;
 
@@ -126,6 +126,7 @@ sub is_tainted_pp {
 
 sub _find_opt {
     my $wanted = shift;
+    return unless @_;
     die "invalid top directory" unless defined $_[0];
 
     # This function must local()ize everything because callbacks may
-- 
2.4.3

@p5pRT
Copy link
Author

p5pRT commented Nov 12, 2015

From @jkeenan

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

On Tue Nov 10 12​:03​:03 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

This is a bug report for perl from Mohammed_ElAfifi@​yahoo.com,
generated with the help of perlbug 1.40 running under perl 5.20.3.

-----------------------------------------------------------------
[Please describe your issue here]

File​::Find​::find(and similarly its cousine finddepth) die when an
empty list of directories is provided. So something like this

find sub {};

will die with a message
"invalid top directory at /usr/share/perl5/File/Find.pm line X."

This makes it a little tedious to test an array before passing it
to find, like this​:

find sub {}, @​directories if @​directories;

or worse if more than one array is used, like this​:

find sub {}, @​dirs1, @​dirs2 if @​dirs1 || @​dirs2;

I've created a trivial patch that would return early if the
provided directory array is empty. The patch also contains a
simple test case to illustrate the problem.

The problem is reproducible on different platforms(windows and
linux) and even on the latest blead sources.

Things I'm not sure I did right​:
- I bumped the version of File​::Find to avoid a failure in some
version comparison test.
- I tried to closely follow the test code style, but don't know
if it's the best way to test this scenario.

Forgot to attach the patches, sorry.

The patches look fine as is. It's therefore a question as to whether we should change File​::Find​::find's behavior as you recommend. If I understand you correctly what you're saying is, "When find() (or finddepth) is presented with an empty list of directories to search, simply return without a warning or die-ing. Only die if the first item in a non-empty list of directories is undefined [the current behavior])."

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 12, 2015

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

@p5pRT
Copy link
Author

p5pRT commented Nov 12, 2015

From @tonycoz

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

Forgot to attach the patches, sorry.

Thanks.

It's generally preferred not to add tests that fail or crash without the fix.

Adding the test as a TODO test is fine, so something like​:

+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+ local $TODO = "find croaks with an empty directory list";
+ ok(eval { find(\&noop_wanted); 1 }, "'find' successfully returned for an empty list of directories");
+
+ ok(eval { finddepth(\&noop_wanted); 1 }, "'finddepth' successfully returned for an empty list of directories");
+}

Or if you prefer I can just squash the two patch together.

Tony

@p5pRT
Copy link
Author

p5pRT commented Nov 12, 2015

From @jkeenan

On Wed Nov 11 16​:53​:45 2015, tonyc wrote​:

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

Forgot to attach the patches, sorry.

Thanks.

It's generally preferred not to add tests that fail or crash without
the fix.

Adding the test as a TODO test is fine, so something like​:

+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+ local $TODO = "find croaks with an empty directory list";
+ ok(eval { find(\&noop_wanted); 1 }, "'find' successfully returned
for an empty list of directories");
+
+ ok(eval { finddepth(\&noop_wanted); 1 }, "'finddepth'
successfully returned for an empty list of directories");
+}

Or if you prefer I can just squash the two patch together.

I applied each patch in a local branch and tested the first before the second. I got the expected test failures on the first and PASS on the second.

So if you're accepting the thrust of the RT, I'd say​: Go ahead and squash the patches and apply.

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 13, 2015

From Mohammed_ElAfifi@yahoo.com

On Wed Nov 11 16​:53​:45 2015, tonyc wrote​:

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

Forgot to attach the patches, sorry.

Thanks.

It's generally preferred not to add tests that fail or crash without
the fix.

Adding the test as a TODO test is fine, so something like​:

+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+ local $TODO = "find croaks with an empty directory list";
+ ok(eval { find(\&noop_wanted); 1 }, "'find' successfully returned
for an empty list of directories");
+
+ ok(eval { finddepth(\&noop_wanted); 1 }, "'finddepth'
successfully returned for an empty list of directories");
+}

Or if you prefer I can just squash the two patch together.

Tony

Thanks everyone for taking the time to review the patch. It's of course perfectly fine with me to squash the patches; it was just that I wrote the test first in its own commit before I changed the code.

@​Tony​: Thanks for refactoring the test; I didn't feel comfortable with my first tests but I didn't have anything else in mind at the time. Wrapping the call in eval would prevent the test from dying when the test is run against the old behavior.

@p5pRT
Copy link
Author

p5pRT commented Nov 14, 2015

From Mohammed_ElAfifi@yahoo.com

On Fri Nov 13 09​:26​:44 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

On Wed Nov 11 16​:53​:45 2015, tonyc wrote​:

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

Forgot to attach the patches, sorry.

Thanks.

It's generally preferred not to add tests that fail or crash without
the fix.

Adding the test as a TODO test is fine, so something like​:

+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+ local $TODO = "find croaks with an empty directory list";
+ ok(eval { find(\&noop_wanted); 1 }, "'find' successfully
returned
for an empty list of directories");
+
+ ok(eval { finddepth(\&noop_wanted); 1 }, "'finddepth'
successfully returned for an empty list of directories");
+}

Or if you prefer I can just squash the two patch together.

Tony

Thanks everyone for taking the time to review the patch. It's of
course perfectly fine with me to squash the patches; it was just that
I wrote the test first in its own commit before I changed the code.

@​Tony​: Thanks for refactoring the test; I didn't feel comfortable with
my first tests but I didn't have anything else in mind at the time.
Wrapping the call in eval would prevent the test from dying when the
test is run against the old behavior.

I consolidated the two patches, along with Tony's suggested refactored tests into this new patch for convenience. Not that I removed the TODO label from the tests since they're now in a single patch along with the fix. I also split the test lines to stay under the 80 chars/line limit.

Regards,
Mohammed.

@p5pRT
Copy link
Author

p5pRT commented Nov 14, 2015

From Mohammed_ElAfifi@yahoo.com

0001-handle-empty-directory-lists-in-File-Find.patch
From c1d87a1c0f0742ede39dda1f96e42a71799c926a Mon Sep 17 00:00:00 2001
From: Mohammed El-Afifi <Mohammed_ElAfifi@yahoo.com>
Date: Mon, 9 Nov 2015 23:49:08 +0200
Subject: [PATCH] handle empty directory lists in File::Find

---
 AUTHORS                        |  1 +
 ext/File-Find/lib/File/Find.pm |  3 ++-
 ext/File-Find/t/find.t         | 12 +++++++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index ebd9222..d56db73 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1271,3 +1271,4 @@ Zefram				<zefram@fysh.org>
 Zsbán Ambrus			<ambrus@math.bme.hu>
 Zbynek Vyskovsky		<kvr@centrum.cz>
 Ævar Arnfjörð Bjarmason		<avar@cpan.org>
+Mohammed El-Afifi		<mohammed_elafifi@yahoo.com>
diff --git a/ext/File-Find/lib/File/Find.pm b/ext/File-Find/lib/File/Find.pm
index 094d5ea..36242d4 100644
--- a/ext/File-Find/lib/File/Find.pm
+++ b/ext/File-Find/lib/File/Find.pm
@@ -3,7 +3,7 @@ use 5.006;
 use strict;
 use warnings;
 use warnings::register;
-our $VERSION = '1.31';
+our $VERSION = '1.32';
 require Exporter;
 require Cwd;
 
@@ -126,6 +126,7 @@ sub is_tainted_pp {
 
 sub _find_opt {
     my $wanted = shift;
+    return unless @_;
     die "invalid top directory" unless defined $_[0];
 
     # This function must local()ize everything because callbacks may
diff --git a/ext/File-Find/t/find.t b/ext/File-Find/t/find.t
index 390f39d..b532752 100644
--- a/ext/File-Find/t/find.t
+++ b/ext/File-Find/t/find.t
@@ -24,7 +24,7 @@ BEGIN {
 }
 
 my $symlink_exists = eval { symlink("",""); 1 };
-my $test_count = 109;
+my $test_count = 111;
 $test_count += 127 if $symlink_exists;
 $test_count += 26 if $^O eq 'MSWin32';
 $test_count += 2 if $^O eq 'MSWin32' and $symlink_exists;
@@ -66,6 +66,16 @@ my $orig_dir = cwd();
 cleanup();
 
 ##### Sanity checks #####
+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+    ok(eval { find(\&noop_wanted); 1 },
+       "'find' successfully returned for an empty list of directories");
+
+    ok(eval { finddepth(\&noop_wanted); 1 },
+       "'finddepth' successfully returned for an empty list of directories");
+}
+
 # Do find() and finddepth() work correctly in the directory
 # from which we start?  (Test presumes the presence of 'taint.t' in same
 # directory as this test file.)
-- 
2.4.3

@p5pRT
Copy link
Author

p5pRT commented Nov 16, 2015

From Mohammed_ElAfifi@yahoo.com

Thanks everyone for taking the time to review the patch. It's of course perfectly fine with me to squash the patches; it was just that I wrote the test first in its own commit before I changed the code.
@​Tony​: Thanks for refactoring the test; I didn't feel comfortable with my first tests but I didn't have anything else in mind at the time. Wrapping the call in eval would prevent the test from dying when the test is run against the old behavior.

  On Thursday, November 12, 2015 4​:06 AM, James E Keenan via RT <perlbug-followup@​perl.org> wrote​:
 

On Wed Nov 11 16​:53​:45 2015, tonyc wrote​:

On Tue Nov 10 14​:15​:38 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

Forgot to attach the patches, sorry.

Thanks.

It's generally preferred not to add tests that fail or crash without
the fix.

Adding the test as a TODO test is fine, so something like​:

+# Do find() and finddepth() work correctly with an empty list of
+# directories?
+{
+    local $TODO = "find croaks with an empty directory list";
+    ok(eval { find(\&noop_wanted); 1 }, "'find' successfully returned
for an empty list of directories");
+
+    ok(eval { finddepth(\&noop_wanted); 1 }, "'finddepth'
successfully returned for an empty list of directories");
+}

Or if you prefer I can just squash the two patch together.

I applied each patch in a local branch and tested the first before the second.  I got the expected test failures on the first and PASS on the second.

So if you're accepting the thrust of the RT, I'd say​:  Go ahead and squash the patches and apply.

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

 

@p5pRT
Copy link
Author

p5pRT commented Nov 16, 2015

From @tonycoz

On Fri Nov 13 22​:51​:12 2015, Mohammed_ElAfifi@​yahoo.com wrote​:

I consolidated the two patches, along with Tony's suggested refactored
tests into this new patch for convenience. Not that I removed the TODO
label from the tests since they're now in a single patch along with
the fix. I also split the test lines to stay under the 80 chars/line
limit.

Thanks, applied as 867fa9e.

Tony

@p5pRT
Copy link
Author

p5pRT commented Nov 16, 2015

@tonycoz - 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
Development

No branches or pull requests

1 participant