This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make taint checking regex compile time instead of runtime
authorKarl Williamson <public@khwilliamson.com>
Tue, 18 Feb 2014 19:59:26 +0000 (12:59 -0700)
committerKarl Williamson <public@khwilliamson.com>
Wed, 19 Feb 2014 21:31:38 +0000 (14:31 -0700)
commit63baef57e83f77e202ae14ef902a6615cf69c8a2
treee9ab630270d9070ec495be7115931cb6a3551939
parentfdf73a7f7fb994c00e17a01f146018fcb3c47ffb
Make taint checking regex compile time instead of runtime

See discussion at https://rt.perl.org/Ticket/Display.html?id=120675
There are several unresolved  items in this discussion, but we did agree
that tainting should be dependent only on the regex pattern, and not the
particular input string being matched against:

"The bottom line is we are moving to the policy that tainting is based
on the operation being in locale, without regard to the particular
operand's contents passed this time to the operation. This means simpler
core code and more consistent tainting results. And it lessens the
likelihood that there are paths in the core that should taint but don't"

This commit does the minimal work to change regex pattern matching to
determine tainting at pattern compilation time.  Simply put, if a
pattern contains a regnode whose match/not match depends on the run-time
locale, any attempt to match against that pattern will taint, regardless
of the actual target string or runtime locale in effect.  Given this
change, there are optimizations that can be made to avoid runtime work,
but these are deferred until later.

Note that just because a regular expression is compiled under locale
doesn't mean that the generated pattern will be tainted.  It depends on
the actual pattern.  For example, the pattern /(.)/ doesn't taint
because it will match exactly one character of the input, regardless of
locale settings.
lib/locale.t
pod/perldelta.pod
pod/perllocale.pod
pp_hot.c
regcomp.c
regexec.c