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
"local *Package::" leads to segfaults and bizarre errors #15059
Comments
From amon@cpan.org#!/usr/bin/env perl BEGIN { sub compile { no strict 'refs'; my $compiled = eval "package $namespace; sub { $source; return }"; return Callback->new($compiled); compile('my $c = q(NoSuchClass); $c->new')->(); __END__ The above program will segfault or produce bizarre errors. Usually, the script dies with:
Clearly, that is wrong. But with some probability (estimated 5% to 100%) we get a segfault instead, which is even worse. This case can be forced by setting the environment variable "PERL_HASH_SEED=8". I can reproduce this behaviour on a variety of perls: - v5.18.2 built for i686-linux-gnu-thread-multi-64int (Ubuntu 14.04 system perl) - v5.20.2 built for x86_64-linux-gnu-thread-multi (Ubuntu 15.10 system perl) I cannot reproduce on v5.10.1 built for i686-linux-thread-multi-64int (perlbrewed). That v5.23.6 perl was a debug build. Running under GDB yielded the following stack trace: (gdb) run testcase Program received signal SIGSEGV, Segmentation fault. If certain details of the script are changed, it behaves as expected and dies with this message:
Why did I write such code in the first place? I was trying to produce code refs by eval'ing their source in individual packages, and making sure the package is cleaned up after the code ref's refcount drops to zero, as to avoid memory leaks. Hence the `local *TheNamespace::` which would restore the previous (empty) package after the code ref has been compiled. The code did previously work without problems, but I didn't track the execution environment closely enough to pinpoint the breaking change. Subtle modifications to the script will produce the expected behaviour (unknown method new) rather than the restricted hash error or the segfault: - returning a bare code ref rather than a blessed object from `compile()`. The attached perlbug information refers to the v5.23.6 build, though other data can be posted on request. Flags: Site configuration information for perl 5.23.6: Configured by atkinson-lukas at Sun Nov 22 22:02:40 CET 2015. Summary of my perl5 (revision 5 version 23 subversion 6) configuration: Locally applied patches: @INC for perl 5.23.6: Environment for perl 5.23.6: |
From @iabynOn Sun, Nov 22, 2015 at 02:40:52PM -0800, Lukas Atkinson wrote:
It can be reduced to the following: sub BAR::new { } my $cb; $cb = eval q{ bless $cb, 'BAR'; which on a debugging blead seems to consistently trigger this assert: perl: hv.c:355: Perl_hv_common: Assertion `((svtype)((hv)->sv_flags & 0xff)) == SVt_PVHV' failed. This is because the method call 'NoSuchClass'->foo tries to find the I'm not sure whether that represents a bug - i.e. I'm not sure whether I'm not sure what to do about this. Arguably *every* COP's CopSTASH() -- |
The RT System itself - Status changed from 'new' to 'open' |
Migrated from rt.perl.org#126709 (status was 'open')
Searchable as RT126709$
The text was updated successfully, but these errors were encountered: