Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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 See this link for an explanation why most alternatives to 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:
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.


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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: monkdiscuss [id://37204]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2017-05-29 07:12 GMT
Find Nodes?
    Voting Booth?