mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-29 15:34:08 +02:00
perl: fix max depth checks in PP
This commit is contained in:
parent
a86c1624a7
commit
bab622de25
@ -124,11 +124,11 @@ sub _unexpected {
|
|||||||
{
|
{
|
||||||
no warnings 'recursion';
|
no warnings 'recursion';
|
||||||
|
|
||||||
my $max_depth;
|
our $_max_depth;
|
||||||
|
|
||||||
sub pack :method {
|
sub pack :method {
|
||||||
Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2;
|
Carp::croak('Usage: Data::MessagePack->pack($dat [,$max_depth])') if @_ < 2;
|
||||||
$max_depth = defined $_[2] ? $_[2] : 512; # init
|
$_max_depth = defined $_[2] ? $_[2] : 512; # init
|
||||||
return _pack( $_[1] );
|
return _pack( $_[1] );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +136,12 @@ sub pack :method {
|
|||||||
sub _pack {
|
sub _pack {
|
||||||
my ( $value ) = @_;
|
my ( $value ) = @_;
|
||||||
|
|
||||||
|
local $_max_depth = $_max_depth - 1;
|
||||||
|
|
||||||
|
if ( $_max_depth < 0 ) {
|
||||||
|
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
||||||
|
}
|
||||||
|
|
||||||
return CORE::pack( 'C', 0xc0 ) if ( not defined $value );
|
return CORE::pack( 'C', 0xc0 ) if ( not defined $value );
|
||||||
|
|
||||||
if ( ref($value) eq 'ARRAY' ) {
|
if ( ref($value) eq 'ARRAY' ) {
|
||||||
@ -146,9 +152,6 @@ sub _pack {
|
|||||||
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdd, $num )
|
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdd, $num )
|
||||||
: _unexpected("number %d", $num)
|
: _unexpected("number %d", $num)
|
||||||
;
|
;
|
||||||
if ( --$max_depth <= 0 ) {
|
|
||||||
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
|
||||||
}
|
|
||||||
return join( '', $header, map { _pack( $_ ) } @$value );
|
return join( '', $header, map { _pack( $_ ) } @$value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +163,6 @@ sub _pack {
|
|||||||
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdf, $num )
|
: $num < 2 ** 32 - 1 ? CORE::pack( 'CN', 0xdf, $num )
|
||||||
: _unexpected("number %d", $num)
|
: _unexpected("number %d", $num)
|
||||||
;
|
;
|
||||||
if ( --$max_depth <= 0 ) {
|
|
||||||
Carp::croak("perl structure exceeds maximum nesting level (max_depth set too low?)");
|
|
||||||
}
|
|
||||||
return join( '', $header, map { _pack( $_ ) } %$value );
|
return join( '', $header, map { _pack( $_ ) } %$value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ my @input = (
|
|||||||
[[],[]],
|
[[],[]],
|
||||||
[{"a" => 97},{"a" => 97}],
|
[{"a" => 97},{"a" => 97}],
|
||||||
[{"a" => 97},{"a" => 97},{"a" => 97}],
|
[{"a" => 97},{"a" => 97},{"a" => 97}],
|
||||||
|
[ map { +{ "foo $_" => "bar $_" } } 'aa' .. 'zz' ],
|
||||||
);
|
);
|
||||||
|
|
||||||
plan tests => @input * 2;
|
plan tests => @input * 2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user