Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: RFC: Perl-Critic policy: ProhibitInlineSystemArgs

by BrowserUk (Patriarch)
on Jul 01, 2006 at 07:22 UTC ( [id://558732]=note: print w/replies, xml ) Need Help??


in reply to Re^2: RFC: Perl-Critic policy: ProhibitInlineSystemArgs
in thread RFC: Perl-Critic policy: ProhibitInlineSystemArgs

Well. Ignoring that you are someone else, explaining someone elses reasoning, and indeed, the reasoning you explain is mostly not yours or the OP's; it will suffice to demonstrate that the OP's PerlCritic code does not even attempt to encapsulate the reasoning you've explained.

The difference between the rule coded and the salient part of your explaination--that is somewhat diluted in your explanation through lack of emphasis and entirely omitted from your quoted reference--is your second sentance:

It can be dangerous if passed unclean user input.

Even in that simple prerequisite there are two conditional parts that are entirely omitted from the rule as coded:

  1. can be
  2. unclean user input

Most Perl scripts are invoked by a user from a shell command line. The user has no need to deviously pass contaminated arguments into Perl scripts in order to have those scripts pass them on to the shell as they can do it directly.

Most system & exec invokations within Perl scripts do not pass unclean user input as a part of their arguments.

Omitting checks in the rule to allow scripts the benefits of reusing the facilities provided by system shells, where doing so does not conflict with security, is like passing a law that says 'noone is allowed to cross a road'.

It can be dangerous to cross a road without looking; but if the road is empty, or if the road is a private road currently closed to vehicular traffic; or if you are of sound mind, with reasonable eyesight, and no mobility impediments and you look first; it's probably okay to cross roads.

Imagine life if a law was imposed upon everyone that they could never cross roads because doing so can sometimes be dangerous if insufficient care is taken when doing so?

Of course, it would be quite difficult to encapsulate the logic required to verify whether a particular use of the single argument system or exec was likely to fall foul of the particular set of circumstances that would render that usage unsafe--but flagging all uses as unsafe because it is easier than performing the checks is not an acceptable alternative.

This is the metaphoric equivalent of imposing a blanket ban on eating out because some chefs are insufficiently aware of the rules for food preparation and might therefore give their client salmonella.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re^3: RFC: Perl-Critic policy: ProhibitInlineSystemArgs

Replies are listed 'Best First'.
Re^4: RFC: Perl-Critic policy: ProhibitInlineSystemArgs
by theorbtwo (Prior) on Jul 01, 2006 at 23:08 UTC

    You've got some good points, but you go a bit too far. There's always a way of coding things that doesn't run afowl of this stricture, and it doesn't involve extra work for the coder. It is also, as a nice side-effect, more efficent, and doesn't have a tendency to make things not work on odd filenames. Just do what the shell would yourself, and pass a list of multiple elements, or when you meant to have a single argument, don't put it in double-quotes.

    Also, ain't nobody (sane) forcing you to use Perl::Critic. I'm not sure if it's lexical or "no"able, though...


    Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

      There's always a way of coding things that doesn't run afowl of this stricture, and it doesn't involve extra work for the coder

      Sorry theorbtwo (nice to see you BTW), but that just isn't so. Take

      system 'myprog | tee mylog | sort >myfile.sorted';

      Perhaps you would consider how little (much) extra work is involved for the coder to achieve the above without using the shell?


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I would write something that would make that easy, something like this, which would take a little more work to output to a file at the end of the pipe, and to use the indirect object syntax of exec, so that even a command with no arguments is (update: slightly more) secure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found