Skip to content

Commit

Permalink
Release 2021.1 fixed cyclic references crash
Browse files Browse the repository at this point in the history
Fixes #33
Fixes #56
  • Loading branch information
hurricup committed Jun 15, 2021
1 parent 5fc6b24 commit 37df788
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Devel-Camelcadedb

2021.1
Fixed crash on cyclic references rendering, #38 #56

2020.3
Taint mode support, by @djstauffer
Typo fixes, by @HenkPoley
Expand Down
33 changes: 27 additions & 6 deletions lib/Devel/Camelcadedb.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package Devel::Camelcadedb;
# must be quoted to work correctly with JSON protocol
our $VERSION = "v2020.3"; # DO NOT REMOVE FUCKING v, IT KEEPS PROPER VERSIONING
our $VERSION = "v2021.1"; # DO NOT REMOVE FUCKING v, IT KEEPS PROPER VERSIONING

# to ensure protocol compatibility between the IDE and the debugger, we will use $API_VERSION variable, to be able
# to bump debugger version without necessity to update IDE part.
Expand Down Expand Up @@ -550,7 +550,7 @@ sub _from_utf8

sub _get_reference_descriptor
{
my ($name, $value) = @_;
my ($name, $value, $uniq_map) = @_;

my $key = $value;
my $reftype = Scalar::Util::reftype( $value );
Expand All @@ -567,6 +567,7 @@ sub _get_reference_descriptor
my $fileno = undef;
my $rendered = undef;
my $rendered_error = \0;
my $error = undef;
my $tied;

if (!$reftype)
Expand All @@ -585,9 +586,18 @@ sub _get_reference_descriptor
}
elsif ($reftype eq 'REF')
{
my $result = _get_reference_descriptor( $name, $$value );
$result->{ref_depth}++;
return $result;
$uniq_map //= {};
if( exists $uniq_map->{$type} ){
$value = "Cyclic reference to $type";
$error = 1;
}
else{
$uniq_map->{$type} = 1;
my $result = _get_reference_descriptor( $name, $$value, $uniq_map );
$result->{ref_depth}++;
return $result;
}

}
elsif ($reftype eq 'ARRAY')
{
Expand Down Expand Up @@ -688,7 +698,18 @@ sub _get_reference_descriptor
}
$result->{layers} = $layers if $layers;
$result->{fileno} = "".$fileno if defined $fileno;
$result->{tied_with} = _get_reference_descriptor(object => $tied) if $tied;
if( $tied){
$uniq_map //= {};
if( exists $uniq_map->{$type} ){
$result->{tied_with} = "Cyclic reference to $type";
$result->{error} = \1;
}
else {
$uniq_map->{$type} = 1;
$result->{tied_with} = _get_reference_descriptor(object => $tied, $uniq_map);
}
}
$result->{error} = \1 if $error;

return $result;
}
Expand Down
23 changes: 23 additions & 0 deletions t/reference_descriptor_serializer.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!perl -T
use v5.10;
use strict;
use warnings;
use Test::More;
use Data::Dumper;

subtest "Cyclic reference" => sub{
$ENV{PERL5_DEBUG_AUTOSTART} = 0;
$ENV{PERL5_DEBUG_ROLE} = 'server';
$ENV{PERL5_DEBUG_HOST} = 'localhost';
$ENV{PERL5_DEBUG_PORT} = 42;
require Devel::Camelcadedb;

my $reference = 'test';
my $reference2 = \$reference;
my $reference3 = \$reference2;
$reference = \$reference3;
DB::_get_reference_descriptor("testname", $reference);
pass();
};

done_testing();

0 comments on commit 37df788

Please sign in to comment.