Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
RE (tilly) 3 (untaint): Warning our Fellow Monksby tilly (Archbishop) |
on Oct 12, 2000 at 00:27 UTC ( [id://36309]=note: print w/replies, xml ) | Need Help?? |
Yes, check for failure. But regular expressions to perfectly secure data passed to the shell are actually pretty easily come by. You just need to remember the cardinal rule, deny everything that is not explicitly allowed. Trying to trap everything that can go wrong is hard. Allowing very limited input, is not. Try the following:
This will work for most filenames you have a reason to allow, and I guarantee you that on a standard Unix system with a standard directory structure (unless someone has placed poor symlinks, etc), there is no way to name anything that passes this which has shell problems. You could test length($1) if you are afraid of buffer overflows. :-) What you will find though is that at some point some developer wants to break the rule. That is fine, just become more lenient (eg allow an optional period in a directory) but step by step keep the philosophy the same. Only that which you have guaranteed safe shall pass.
In Section
Perl Monks Discussion
|
|