CC: | 460423 [...] rt.noris.net |
Subject: | ininite loop in Locale::Maketext::Guts::_compile() when working with tainted values |
A CGI application I'm writing was just running in an infinite loop that
I could track down in Locale::Maketext::Guts::_compile().
The reason is that several (including current) versions of the Perl
interpreter seem to have a bug with pattern matching operations
involving \G on tainted values, cmp. my perl bug report #60378:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pos() and regex matching with \G does not work if a tainted value
is passed to a sub routine:
$ perl -Tle '$_=shift; /\G(.*)/g; print pos || "-"' foo
3
$ perl -le 'x(shift); sub x { $_[0] =~ /\G(.*)/g; print pos $_[0] ||
"-" }' foo
3
$ perl -Tle 'x(shift); sub x { $_[0] =~ /\G(.*)/g; print pos $_[0] ||
"-" }' foo
-
This e.g. causes infinite loops in Locale::Maketext::Guts::_compile().
It works, however, if the value is assigned to a variable first
and then this variable is used for the matching operation:
$ perl -Tle 'x(shift); sub x { my $s = shift; $s =~ /\G(.*)/g; print pos
$s || "-" }' foo
3
The issue not only affects the perl version mentioned below but
also the standard perl v5.8.8 interpreter built for
i486-linux-gnu-thread-multi on Debian/Etch and thus probably
other versions, too.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Even if this is considered a Perl bug and will hopefully be fixed some
day, I think it would be reasonable to have a workaround in
Locale::Maketext::Guts::compile(), too, in order to have the module work
with current Perl versions.
A simple solution would be not to match on $_[1] but to assign "my $var
= $_[1];" before and then use $var for the matching operation.
BTW, if you're wondering how a tainted value gets there anyway:
One of my templates refers to my CGI::Application's current runmode,
which is submitted by the client. I was really puzzled at first,
because my application worked for one langugage, which I use
Locale::Maketext::Lexicon::Gettext for, but got stuck for certain
(tainted) values in conjunction with Locale::Maketext::Lexicon::Auto
when switching to another language.
Regards,
fany