Skip Menu |
 

This queue is for tickets about the File-Find-Rule CPAN distribution.

Report information
The Basics
Id: 64504
Status: new
Priority: 0/
Queue: File-Find-Rule

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: grep() can truncate files
Date: Thu, 06 Jan 2011 07:47:10 +1100
To: bug-File-Find-Rule [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 678b
With File::Find::Rule and recent debian i386 perl 5.10.1, the program foo.pl below truncates file /tmp/zzz/foo to zero length, where I hoped a File::Find::Rule grep() would be read-only. I think the filename ">foo" in the directory causes open FILE, $_ or return; to overwrite the "foo" file. I suppose only the 3-arg open treats all weird filenames properly. If staying 2-arg for older perl compatibility then a "<$filename", or a "<./$filename" if not an absolute filename already, might help avoid the worst. Either way it could be worth showing 3-arg in the POD sample exec() under the "Further examples", to keep cut-and-paste users out of this kind of trouble.
Download foo.pl
text/x-perl 340b
# create two files /tmp/zzz/foo and /tmp/zzz/>foo system " rm -r /tmp/zzz mkdir /tmp/zzz echo abc def >/tmp/zzz/foo echo abc def >'/tmp/zzz/>foo' ls -l /tmp/zzz "; # grep them ... use File::Find::Rule; my @files = File::Find::Rule->grep('abc')->in('/tmp/zzz'); # /tmp/zzz/foo has been truncated to 0 length ... system ("ls -l /tmp/zzz");


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.