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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|