Skip to content

Reentrance issue — $convert_blessed etc. are global variables and may be clobbered #61

@domq

Description

@domq

The settings variables are global variables (although not visible in a global scope); they may be clobbered by a reentrant call to JSON::PP.

Here is a minimal test case demonstrating the problem:

use JSON;

sub MyClass::new { bless {}, shift }
sub MyClass::TO_JSON { encode_json([]) }

my $jsonist = JSON->new->convert_blessed;
print "So far, so good:\n";
print $jsonist->encode([MyClass->new]);
print "But the next line will crash:\n";
print $jsonist->encode([MyClass->new, MyClass->new]);

In the last line, the “JSONificiation” of a first MyClass->new instance goes through the TO_JSON method, which changes the global variables, which prevents the “JSONification” of the second object.

All the settings variables should be refactored as instance properties of the object returned by JSON->new.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions