Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Why We Use Strict!

by Ovid (Cardinal)
on Oct 17, 2000 at 22:03 UTC ( #37204=monkdiscuss: print w/replies, xml ) Need Help??

Time and time again, we hear Monks admonish others that they should use strict;. Well, here's a great example why.

Routinely, I see in people's code use strict; with no strict 'refs'; later in the code. Typically, when I see this, my mind screams "Danger, Will Robinson, Danger!" (which is rather odd as my given name is actually "Curtis"). Consider the following code that I ran across today:

if ($main::stateIn{'sibling'}) { no strict 'refs'; &{$main::stateIn{'sibling'}}(); }
First, the $main::stateIn{} hash is fully qualified because the developer apparently didn't know the difference between package and lexical variables. Second, $main::stateIn{} is how he gets the CGI parameters. Yup, you guessed it! He wrote a broken alternative to CGI.pm. See this link for an explanation why most alternatives to CGI.pm are flawed. In this case, the developer's alternative had all of the classic errors detailed in the aforementioned link. However, what we're really interested in is the following line:
&{$main::stateIn{'sibling'}}();
Since the developer had no strict 'refs'; before this, and since the developer also didn't bother to employ taint checking, that snippet above will allow a cracker to execute any frickin' subroutine they want so long as the main program can call it. The program in question uses many different modules which, in turn, use other modules. There are literally hundreds of different subs that could be called, with unknown consequences. Admittedly, you can't pass any params to those subs, but that's one HECK of a security hole.

Just use strict; folks.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: monkdiscuss [id://37204]
Approved by root
help
Chatterbox?
[LanX]: it was just after Trump-ageddon and the Americans thought I'm ridiculing them ;)
Discipulus was not the title a bit provoking? ;=)
[LanX]: I have a degree in cynism. ..
LanX is the PROVO-KING

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-11-20 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (292 votes). Check out past polls.

    Notices?