Skip to content

Commit

Permalink
Re: [perl #41442] segfault (dead loop) with Encoding, use open :local…
Browse files Browse the repository at this point in the history
…e, print STDERR

Message-ID: <87veiggt2g.fsf@biokovo.herceg.de>

p4raw-id: //depot/perl@30213
  • Loading branch information
eserte authored and rgs committed Feb 11, 2007
1 parent 66b9418 commit 74f6c1c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ ext/PerlIO/encoding/encoding.pm PerlIO::encoding
ext/PerlIO/encoding/encoding.xs PerlIO::encoding
ext/PerlIO/encoding/Makefile.PL PerlIO::encoding makefile writer
ext/PerlIO/encoding/MANIFEST PerlIO::encoding list of files
ext/PerlIO/encoding/t/nolooping.t Tests for PerlIO::encoding
ext/PerlIO/scalar/Makefile.PL PerlIO layer for scalars
ext/PerlIO/scalar/scalar.pm PerlIO layer for scalars
ext/PerlIO/scalar/scalar.xs PerlIO layer for scalars
Expand Down
2 changes: 1 addition & 1 deletion ext/PerlIO/encoding/encoding.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package PerlIO::encoding;

use strict;
our $VERSION = '0.09';
our $VERSION = '0.10';
our $DEBUG = 0;
$DEBUG and warn __PACKAGE__, " called by ", join(", ", caller), "\n";

Expand Down
12 changes: 11 additions & 1 deletion ext/PerlIO/encoding/encoding.xs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ typedef struct {
SV *enc; /* the encoding object */
SV *chk; /* CHECK in Encode methods */
int flags; /* Flags currently just needs lines */
int inEncodeCall; /* trap recursive encode calls */
} PerlIOEncode;

#define NEEDS_LINES 1
Expand Down Expand Up @@ -147,6 +148,7 @@ PerlIOEncode_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, PerlIO_funcs *
}

e->chk = newSVsv(get_sv("PerlIO::encoding::fallback", 0));
e->inEncodeCall = 0;

FREETMPS;
LEAVE;
Expand Down Expand Up @@ -404,6 +406,7 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
STRLEN len;
SSize_t count = 0;
if ((PerlIOBase(f)->flags & PERLIO_F_WRBUF) && (e->base.ptr > e->base.buf)) {
if (e->inEncodeCall) return 0;
/* Write case - encode the buffer and write() to layer below */
PUSHSTACKi(PERLSI_MAGIC);
SPAGAIN;
Expand All @@ -416,9 +419,12 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
XPUSHs(e->bufsv);
XPUSHs(e->chk);
PUTBACK;
e->inEncodeCall = 1;
if (call_method("encode", G_SCALAR) != 1) {
e->inEncodeCall = 0;
Perl_die(aTHX_ "panic: encode did not return a value");
}
e->inEncodeCall = 0;
SPAGAIN;
str = POPs;
PUTBACK;
Expand Down Expand Up @@ -453,6 +459,7 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
}
/* See if there is anything left in the buffer */
if (e->base.ptr < e->base.end) {
if (e->inEncodeCall) return 0;
/* Bother - have unread data.
re-encode and unread() to layer below
*/
Expand All @@ -472,9 +479,12 @@ PerlIOEncode_flush(pTHX_ PerlIO * f)
XPUSHs(str);
XPUSHs(e->chk);
PUTBACK;
e->inEncodeCall = 1;
if (call_method("encode", G_SCALAR) != 1) {
Perl_die(aTHX_ "panic: encode did not return a value");
e->inEncodeCall = 0;
Perl_die(aTHX_ "panic: encode did not return a value");
}
e->inEncodeCall = 0;
SPAGAIN;
str = POPs;
PUTBACK;
Expand Down
9 changes: 9 additions & 0 deletions ext/PerlIO/encoding/t/nolooping.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!perl -w

use Test::More tests => 1;

# bug #41442
use open ':locale';
if (-e '/dev/null') { open STDERR, '>', '/dev/null' }
warn "# \x{201e}\n"; # &bdquo;
ok(1); # we got that far

0 comments on commit 74f6c1c

Please sign in to comment.