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

segfault on opening tied and blessed handle #16138

Open
p5pRT opened this issue Sep 9, 2017 · 6 comments
Open

segfault on opening tied and blessed handle #16138

p5pRT opened this issue Sep 9, 2017 · 6 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 9, 2017

Migrated from rt.perl.org#132048 (status was 'open')

Searchable as RT132048$

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2017

From @haukex

Hi,

The attached script segfaults on Perl 5.26.0 (perlbug output is included
at the end of the file). On older Perls (tested on 5.10), it appears to
drop into an infinite loop. While I'm not sure whether blessing the tied
handle itself is a sane thing to do (I was just playing around with tied
handles), I'm pretty sure it shouldn't segfault.

Thanks, Regards,
-- Hauke D

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2017

From @haukex

tiedhandle_segfault.pl

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2017

From zefram@fysh.org

Hauke D wrote​:

                       While I'm not sure whether blessing the tied 

handle itself is a sane thing to do

What you're doing gets weird earlier than that. Your tie call​:

  tie *$fh, 'Kaboom', $fh;

is pretty strange. Normally the arguments coming after the class name
do not refer to the thing being tied, but only tell the class how this
tied thing should behave. It's also strange for the TIEHANDLE method
to return an argument as the tie-mediating object​: normally it would
construct and return a new object for this purpose.

Given how you've overloaded this object to have multiple roles, it's not
surprising that there would be some misbehaviour. In fact, since the
default behaviour supplied by Tie​::StdHandle is to implement operations on
the tied handle as the same operations on the tie-mediating object, the
expected behaviour here is an infinite recursion as soon as you attempt
a tied operation (such as opening). That's the behaviour that I see, for
your test program, on every major stable version from 5.10.0 to 5.26.0.

     I'm pretty sure it shouldn't segfault\.

Yes, we'd like to avoid that.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2017

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 9, 2017

From @jkeenan

On 09/09/2017 10​:20 AM, Hauke D wrote​:

# New Ticket Created by Hauke D
# Please include the string​: [perl #132048]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=132048 >

Hi,

The attached script segfaults on Perl 5.26.0 (perlbug output is included
at the end of the file). On older Perls (tested on 5.10), it appears to
drop into an infinite loop. While I'm not sure whether blessing the tied
handle itself is a sane thing to do (I was just playing around with tied
handles), I'm pretty sure it shouldn't segfault.

Thanks, Regards,
-- Hauke D

I can confirm that removing the 'bless' enables the program to exit
normally.

@p5pRT
Copy link
Author

p5pRT commented Sep 22, 2017

From @haukex

On 09.09.2017 17​:48, Zefram via RT wrote​:

What you're doing gets weird earlier than that.

Agreed :-) This was a "let's see what happens when I do this" kind of
experiment - thank you for your explanation as to what exactly is going
wrong. My actual code uses two filehandles.

Regards,
-- Hauke D

On 09.09.2017 17​:48, Zefram via RT wrote​:

Hauke D wrote​:

                        While I'm not sure whether blessing the tied

handle itself is a sane thing to do

What you're doing gets weird earlier than that. Your tie call​:

tie \*$fh\, 'Kaboom'\, $fh;

is pretty strange. Normally the arguments coming after the class name
do not refer to the thing being tied, but only tell the class how this
tied thing should behave. It's also strange for the TIEHANDLE method
to return an argument as the tie-mediating object​: normally it would
construct and return a new object for this purpose.

Given how you've overloaded this object to have multiple roles, it's not
surprising that there would be some misbehaviour. In fact, since the
default behaviour supplied by Tie​::StdHandle is to implement operations on
the tied handle as the same operations on the tie-mediating object, the
expected behaviour here is an infinite recursion as soon as you attempt
a tied operation (such as opening). That's the behaviour that I see, for
your test program, on every major stable version from 5.10.0 to 5.26.0.

      I'm pretty sure it shouldn't segfault\.

Yes, we'd like to avoid that.

-zefram

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