summaryrefslogtreecommitdiff
path: root/ext/Digest/MD5/t/badfile.t
blob: 90a7857ac39108ba95b472c8b624f3a19de78a0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Digest::MD5 2.07 and older used to trigger a core dump when
# passed an illegal file handle that failed to open.

print "1..3\n";

use Digest::MD5 ();
use Config;

$md5 = Digest::MD5->new;

eval {
   use vars qw(*FOO);
   $md5->addfile(*FOO);
};
print "not " unless $@ =~ /^Bad filehandle: FOO at/;
print "ok 1\n";

open(BAR, "no-existing-file.$$");
eval {
    $md5->addfile(*BAR);
};
print "not " unless $@ =~ /^No filehandle passed at/;
print "ok 2\n";

open(BAR, ">no-existing-file.$$") || die;
eval {
    $md5->addfile(*BAR);
};
# Some stdio implementations don't find reading from
# write-only filehandle to be a problem.  Therefore we
# cannot expect this to fail reliably with stdio.
my $stdio = !exists  $Config{useperlio} ||
	    !defined $Config{useperlio} ||
	    (exists $ENV{PERLIO} && $ENV{PERLIO} eq 'stdio');
print "not " unless $@ =~ /^Reading from filehandle failed at/ || $stdio;
print "ok 3\n";

close(BAR);
unlink("no-existing-file.$$");