Blame t/retrieve.t

Packit 14c646
#!./perl
Packit 14c646
#
Packit 14c646
#  Copyright (c) 1995-2000, Raphael Manfredi
Packit 14c646
#  Copyright (c) 2017, cPanel Inc
Packit 14c646
#  
Packit 14c646
#  You may redistribute only under the same terms as Perl 5, as specified
Packit 14c646
#  in the README file that comes with the distribution.
Packit 14c646
#
Packit 14c646
Packit 14c646
sub BEGIN {
Packit 14c646
    unshift @INC, 'dist/Storable/t' if $ENV{PERL_CORE} and -d 'dist/Storable/t';
Packit 14c646
    unshift @INC, 't';
Packit 14c646
    unshift @INC, 't/compat' if $] < 5.006002;
Packit 14c646
    require Config; import Config;
Packit 14c646
    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
Packit 14c646
        print "1..0 # Skip: Storable was not built\n";
Packit 14c646
        exit 0;
Packit 14c646
    }
Packit 14c646
    require 'st-dump.pl';
Packit 14c646
}
Packit 14c646
Packit 14c646
Packit 14c646
use Storable qw(store retrieve nstore);
Packit 14c646
use Test::More tests => 20;
Packit 14c646
Packit 14c646
$a = 'toto';
Packit 14c646
$b = \$a;
Packit 14c646
$c = bless {}, CLASS;
Packit 14c646
$c->{attribute} = 'attrval';
Packit 14c646
%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
Packit 14c646
@a = ('first', '', undef, 3, -4, -3.14159, 456, 4.5,
Packit 14c646
	$b, \$a, $a, $c, \$c, \%a);
Packit 14c646
Packit 14c646
isnt(store(\@a, "store$$"), undef);
Packit 14c646
is(Storable::last_op_in_netorder(), '');
Packit 14c646
isnt(nstore(\@a, 'nstore'), undef);
Packit 14c646
is(Storable::last_op_in_netorder(), 1);
Packit 14c646
is(Storable::last_op_in_netorder(), 1);
Packit 14c646
Packit 14c646
$root = retrieve("store$$");
Packit 14c646
isnt($root, undef);
Packit 14c646
is(Storable::last_op_in_netorder(), '');
Packit 14c646
Packit 14c646
$nroot = retrieve('nstore');
Packit 14c646
isnt($root, undef);
Packit 14c646
is(Storable::last_op_in_netorder(), 1);
Packit 14c646
Packit 14c646
$d1 = &dump($root);
Packit 14c646
isnt($d1, undef);
Packit 14c646
$d2 = &dump($nroot);
Packit 14c646
isnt($d2, undef);
Packit 14c646
Packit 14c646
is($d1, $d2);
Packit 14c646
Packit 14c646
# Make sure empty string is defined at retrieval time
Packit 14c646
isnt($root->[1], undef);
Packit 14c646
is(length $root->[1], 0);
Packit 14c646
Packit 14c646
# $Storable::DEBUGME = 1;
Packit 14c646
{
Packit 14c646
    # len>I32: todo patch the storable image number into the strings, fake 2.10
Packit 14c646
    # $Storable::BIN_MINOR
Packit 14c646
    my $retrieve_blessed = "\x04\x0a\x08\x31\x32\x33\x34\x35\x36\x37\x38\x04\x08\x08\x08\x11\xff\x49\x6e\x74\xff\x72\x6e\x61\x6c\x73\x02\x00\x00\x00\x00";
Packit 14c646
    my $x = eval { Storable::mretrieve($retrieve_blessed); };
Packit 14c646
    # Long integer or Double size or Byte order is not compatible
Packit 14c646
    like($@, qr/^(Corrupted classname length|.* is not compatible|panic: malloc)/, "RT #130635 $@");
Packit 14c646
    is($x, undef, 'and undef result');
Packit 14c646
}
Packit 14c646
Packit 14c646
{
Packit 14c646
    # len>I32
Packit 14c646
    my $retrieve_hook = "\x04\x0a\x08\x31\x32\x33\x34\x35\x36\x37\x38\x04\x08\x08\x08\x13\x04\x49\xfe\xf4\xff\x72\x6e\x61\x6c\x73\x02\x00\x00\x00\x00";
Packit 14c646
    my $x = eval { Storable::mretrieve($retrieve_hook); };
Packit 14c646
    like($@, qr/^(Corrupted classname length|.* is not compatible|panic: malloc)/, "$@");
Packit 14c646
    is($x, undef, 'and undef result');
Packit 14c646
}
Packit 14c646
Packit 14c646
{
Packit 14c646
    # len<I32, len>127: stack overflow
Packit 14c646
    my $retrieve_hook = "\x04\x0a\x08\x31\x32\x33\x34\x35\x36\x37\x38\x04\x08\x08\x08\x13\x04\x49\xfe\xf4\x7f\x72\x6e\x61\x6c\x73\x02\x00\x00\x00\x00";
Packit 14c646
    my $x = eval { Storable::mretrieve($retrieve_hook); };
Packit 14c646
    is($?, 0, "no stack overflow in retrieve_hook()");
Packit 14c646
    is($x, undef, 'either out of mem or normal error (malloc 2GB)');
Packit 14c646
}
Packit 14c646
Packit 14c646
END { 1 while unlink("store$$", 'nstore') }