Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Not Strictly A perl question.

by Zaxo (Archbishop)
on Jul 01, 2001 at 00:19 UTC ( #92952=note: print w/replies, xml ) Need Help??


in reply to Re: Not Strictly A perl question.
in thread Not Strictly A perl question.

I'll fill out some of the bits jepri left out

As it stands the code has a classic cgi security hole. It trusts user input for file system locations (e.g. ?image=/etc/passwd). Here is a safer rewrite:

#!/usr/local/bin/perl -wT use strict; use CGI qw/:all/; my %images = ( 'tophat'=> { 'path'=>"/usr/somewhere/way/out/of/reach/Top Hat.jpeg", 'mime'=>"image/jpeg"}, 'racecar'=> { 'path'=>"/usr/somewhere/way/out/of/reach/Bugatti.png", 'mime'=>"image/png"}, #etc... ); my $query = CGI::new(); my $file = $query->param("image"); $|=1; if (defined $images{$file}) { print $query->header({-type=>$images{$file}{'mime'}});} open ( IMAGE, $images{$file}{'path'} ); print while ( <IMAGE> ); close(IMAGE); } else { print $query->header({-type=>'text/html', -status=>"404 File Not Found"}); } exit ;

This is a forgiving approach to bad input, more BOFHish to log and play games.

After Compline,
Zaxo

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://92952]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2023-11-30 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?