I was trying to fix some code today that was attempting to do delayed string interpolation. Something like:
$str = 'Foo: $foo'; # Actually defined in a config file. $foo = 'bar'; # ...later
print eval("\$str"), "\n";
Foo: $foo
print eval(qq{"$str"}), "\n";
eval { $text =~ s/(\$\w+)/$1/eeg }; die if $@;
$str = '", print(qq!you lose\n!),"'
eval(qq{"$str"})
# you lose
Re:asdlfkjhasdglk
Aristotle on 2007-06-01T07:08:57
eval qq{"\Q$str\E"}Re:asdlfkjhasdglk
educated_foo on 2007-06-01T12:53:12
Right you are.Re:asdlfkjhasdglk
stu42j on 2007-06-01T13:54:38
Well, that fixes the malicious entry problem but it also defeats the original purpose. The \Q\E prevents the string from ever getting interpolated and you are back to 'Foo: $bar'.Re:asdlfkjhasdglk
stu42j on 2007-06-01T13:55:33
In this case, the string is safe but thanks for the warning.