in reply to Re^2: Search for text from user input
in thread Search for text from user input
Update: This was intended as an answer to re ^2; specifically, how to untaint. Apologies for any confusion caused by my confusion. :-)
Anonymonk gave you the bullet version; sierpinski provided the details. Very simply, write a regular expression to reject anything which is NOT acceptable -- for your purposes, acceptable input might well be constrained to
/^[A-Za-z0-9]+\.jpg$/i...that is, a name beginning with an upper or lowercase alpha character or a digit, followed by any number of alphas or digits, followed by a period and "jpg". The "^" and "$"mark the beginning and end of your $search string, thus preventing someone from sending you a file called
foo.jpg.delete_everything.exe.Alternately, your could reject everything except the char set just discussed by using
/^[^A-Za-z0-9]+\.jpg$/i...which is the inverse set-- anything that is NOT an upper or lowercase alpha or digit matches, in which case you would want to reject anything that DOES match this one. (if you wish to accept "*.jpeg" you'll need to extend these regexen.)
BTW, the shebang is better written as
#!/usr/bin/perl -wTI suspect your version will fail. And, for your own sanity and safety:
And, as to your question in re ^3, consider: Where do you expect the value of $_ to come from? Again, see walkingthecow's answer, below.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Search for text from user input
by ww (Archbishop) on May 13, 2010 at 13:56 UTC |