Skip to content

Commit

Permalink
[perl #111610] Trouble with XS-APItest/t/clone-with-stack.t
Browse files Browse the repository at this point in the history
I ran into a bit of a problem when building perl-5.16.0.
'make test' showed a segfault in ext/XS-APItest/t/clone-with-stack.t.
It seems to be caused by accessing already freed memory, it
segfaults because I have MALLOC_PERTUBE_ set, thus glibc fills
freed memory with some value.

Digging deeper, it seems like perl_clone() does not fix
the cx's blk_oldcop element when doing context cloning, thus
blk_oldcop still points to PL_compiling in the old interp--the
calling scope for the BEGIN block being the compilation of the
code surrounding it--and the POPBLOCK done in leavesub will copy
the data from the old interp to PL_curcop.

After fixing this, it still crashed because interp_dup->Iop was
zero after the runops_standard() call (which is probably
correct as the end of the BEGIN block was reached). So I
also added an if statement that checks the pointer.
  • Loading branch information
mlschroe authored and Father Chrysostomos committed Jun 9, 2012
1 parent d5db65c commit 4a808ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/XS-APItest/APItest.xs
Expand Up @@ -3084,7 +3084,8 @@ CODE:
PERL_SET_CONTEXT(interp_dup);

/* continue after 'clone_with_stack' */
interp_dup->Iop = interp_dup->Iop->op_next;
if (interp_dup->Iop)
interp_dup->Iop = interp_dup->Iop->op_next;

/* run with new perl */
Perl_runops_standard(interp_dup);
Expand Down
1 change: 1 addition & 0 deletions sv.c
Expand Up @@ -12312,6 +12312,7 @@ Perl_cx_dup(pTHX_ PERL_CONTEXT *cxs, I32 ix, I32 max, CLONE_PARAMS* param)
Perl_croak(aTHX_ "Cloning substitution context is unimplemented");
}
else {
ncx->blk_oldcop = (COP*)any_dup(ncx->blk_oldcop, param->proto_perl);
switch (CxTYPE(ncx)) {
case CXt_SUB:
ncx->blk_sub.cv = (ncx->blk_sub.olddepth == 0
Expand Down

0 comments on commit 4a808ed

Please sign in to comment.