Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: User regexps

by liz (Monsignor)
on Jan 14, 2004 at 15:03 UTC ( [id://321266]=note: print w/replies, xml ) Need Help??


in reply to User regexps

...This is all wrapped in an eval, so I catch badly formed regexps; I am worried about intentional or unintentional ill-effects beyond an error...

You should use taint.

You should be aware of what use re 'eval' allows you to do with regular expressions.

And you should of course be aware of source code injection. Suppose the user specifies: "a/; system( 'some evil command' ); m/a" and your code is:

eval "m/$query/";
you're in deep trouble.

Liz

Replies are listed 'Best First'.
Re: User regexps
by Abigail-II (Bishop) on Jan 14, 2004 at 15:39 UTC
    And you should of course be aware of source code injection. Suppose the user specifies: "a/; system( 'some evil command' ); m/a" and your code is:
    eval "m/$query/";
    But that's not the code! Read the post. The code is:
    my $re = $_->regex; $matchtext =~ /$re/i;
    There's no danger of source code injection here (unless there's an unseen use re 'eval' in an enclosing scope.

    Abigail

      Took me a while to understand why the second was safe and the first wasn't. Thanks for putting them side by side, clearly labeled, for me to think about. I would have used the second without worry, and the first (anything with an eval on user data) always worries me, but that's just habbit. Looking at these two examples bumped it back up to real understanding again, which is always nice.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-24 01:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found