Fix segfault in filehandle duplication
authorLeon Timmermans <fawaka@gmail.com>
Sat, 7 Sep 2013 06:58:18 +0000 (08:58 +0200)
committerLeon Timmermans <fawaka@gmail.com>
Sat, 7 Sep 2013 07:01:42 +0000 (09:01 +0200)
Previously PerlIOBase_dup didn't check if pushing the new layer succeeded
before (optionally) setting the utf8 flag. This could cause
segfaults-by-nullpointer.

perlio.c

index f7c0698..7e6ceae 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -2309,7 +2309,7 @@ PerlIOBase_dup(pTHX_ PerlIO *f, PerlIO *o, CLONE_PARAMS *param, int flags)
        if (self && self->Getarg)
            arg = (*self->Getarg)(aTHX_ o, param, flags);
        f = PerlIO_push(aTHX_ f, self, PerlIO_modestr(o,buf), arg);
-       if (PerlIOBase(o)->flags & PERLIO_F_UTF8)
+       if (f && PerlIOBase(o)->flags & PERLIO_F_UTF8)
            PerlIOBase(f)->flags |= PERLIO_F_UTF8;
        SvREFCNT_dec(arg);
     }