Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
domq opened this issue Mar 20, 2022 · 1 comment

Comments

@domq
Copy link

domq commented Mar 20, 2022

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.

@FractalBoy
Copy link

I just hit this issue as well. It has been open for only a year in a core Perl module - is there any likelihood of it being fixed? Otherwise I'll open an issue in the Perl github.

charsbar added a commit that referenced this issue Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants