Skip to content

Commit

Permalink
Close the eval "require $module" security hole in Digest->new($algori…
Browse files Browse the repository at this point in the history
…thm)

Also the filter was incomplete.
  • Loading branch information
schwern committed Oct 2, 2011
1 parent 517c704 commit 33800e8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Digest.pm
Expand Up @@ -24,7 +24,7 @@ sub new
shift; # class ignored
my $algorithm = shift;
my $impl = $MMAP{$algorithm} || do {
$algorithm =~ s/\W+//;
$algorithm =~ s/\W+//g;
"Digest::$algorithm";
};
$impl = [$impl] unless ref($impl);
Expand All @@ -35,7 +35,9 @@ sub new
($class, @args) = @$class if ref($class);
no strict 'refs';
unless (exists ${"$class\::"}{"VERSION"}) {
eval "require $class";
my $pm_file = $class . ".pm";
$pm_file =~ s{::}{/}g;
eval { require $pm_file };
if ($@) {
$err ||= $@;
next;
Expand Down
14 changes: 14 additions & 0 deletions t/security.t
@@ -0,0 +1,14 @@
#!/usr/bin/env perl

# Digest->new() had an exploitable eval

use strict;
use warnings;

use Test::More tests => 1;

use Digest;

$LOL::PWNED = 0;
eval { Digest->new(q[MD;5;$LOL::PWNED = 42]) };
is $LOL::PWNED, 0;

0 comments on commit 33800e8

Please sign in to comment.