|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: Strange Perl Script Behavior
|
On Mon, Sep 30, 2002 at 08:05:45PM -0400, David Steuber wrote:
| sub wanted {
| if (/^([-\@\w.]+)$/) {
| push @image_files, $1; # this untaints the file names
| }
| }
this scoops up directories as well as files. add a ! -d.
| find({ wanted => \&wanted, untaint => 1 }, Dir());
| my $chosen_file = Dir() . '/' . $image_files[int(rand(scalar(@image_files)))];
preloading the entire set of image files is slow. maybe the "How do I
select a random line from a file?" algorithm from perlfaq5 could help here.
| my $file_type = `/usr/bin/file $chosen_file`;
|
| my $content_type = 'text/plain';
| if ($file_type =~ / GIF /) {
| $content_type = 'image/gif';
| } elsif ($file_type =~ / JPEG /) {
| $content_type = 'image/jpeg';
| } elsif ($file_type =~ / PNG /) {
| $content_type = 'image/png';
| }
maybe Imager or http://search.cpan.org/author/SDAGUE/ppt-0.12/bin/file
could do this more effectively? that way you don't have to worry about
untainting. they might be slower, though --- benchmark.
|
| david@apostrophe:/websites/david-steuber.com/pix/images-cgi
| $ ./mesg-sig.cgi
| Expires: Tue, 01 Oct 2002 00:33:30 GMT
| Date: Mon, 30 Sep 2002 23:33:30 GMT
| Content-Type: text/plain; charset=ISO-8859-1
|
| /websites/david-steuber.com/pix/mesg-board/sig-images/.: directory
|
adding a ! -d above should help.
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|