Running Solaris/x86 2.5.1; perl -v reports:
This is perl, version 5.004_01
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Eval will fail in the following situation:
- eval'ing a string
- the string represents an anonymous hash
- the first key of the anon hash is single quoted, and contains an
embedded single quote escaped with a backslash
- using the form `` $ref = eval $string ''
The MLDBM module uses this form of eval all the time, so the above
situation actually has the potential to occur quite often.
This script demonstrates the bug:
------------------------------------------------------------------------
#! /opt/perl5/bin/perl
$string1 = "{'a' => 'foo', 'b' => 'bar', 'c' => 'bat'}";
$string2 = "{'a\\'' => 'foo', 'b' => 'bar', 'c' => 'bat'}";
$string3 = "{'a' => 'foo', 'b\\'' => 'bar', 'c' => 'bat'}";
evalit($string1);
evalit($string2);
evalit($string3);
sub evalit {
my $string = shift;
print "String is ", $string, "\n";
$ref = eval $string;
print 'First eval form: $ref is a ', ref($ref), "\n";
print "ref's value is $ref\n" unless ref($ref) eq "HASH";
print map {" $_: $ref->{$_}\n"} keys %{$ref};
eval "\$ref = $string";
print "ref's value is $ref\n" unless ref($ref) eq "HASH";
print 'Second eval form: $ref is a ', ref($ref), "\n";
print map {" $_: $ref->{$_}\n"} keys %{$ref};
print "\n";
Quote:
}
------------------------------------------------------------------------
$ ./showbug
String is {'a' => 'foo', 'b' => 'bar', 'c' => 'bat'}
First eval form: $ref is a HASH
a: foo
b: bar
c: bat
Second eval form: $ref is a HASH
a: foo
b: bar
c: bat
String is {'a\'' => 'foo', 'b' => 'bar', 'c' => 'bat'}
First eval form: $ref is a
ref's value is bat
Second eval form: $ref is a HASH
a': foo
b: bar
c: bat
String is {'a' => 'foo', 'b\'' => 'bar', 'c' => 'bat'}
First eval form: $ref is a HASH
b': bar
a: foo
c: bat
Second eval form: $ref is a HASH
b': bar
a: foo
c: bat
------------------------------------------------------------------------
--
Edmonton, Alberta, Canada | traditional!