diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-10-28 21:59:14 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-12-21 18:09:54 -0800 |
commit | c1cec775e9019cc8ae244d4db239a7ea5c0b343e (patch) | |
tree | f2c2393343552b8a6e74bce1257e8770413d1839 /mg.c | |
parent | bb02e0c10a57ab28b9ec6ca218c7aa6aac53a90c (diff) | |
download | perl-c1cec775e9019cc8ae244d4db239a7ea5c0b343e.tar.gz |
[perl #119801] Stop @DB::dbline modifications from crashing
The cop address for each breakable line was being stored in the IVX
slot of ${"_<$file"}[$line]. This value itself, writable from Perl
space, was being used as the address of the op to be flagged, whenever
a breakpoint was set.
This meant writing to ${"_<$file"}[$line] and assigning a number (like
42) would cause perl to use 42 as an op address, and crash when trying
to flag the op.
Furthermore, since the array holding the lines could outlive the ops,
setting a breakpoint on the op could write to freed memory or to an
unrelated op (even a different type), potentially changing the beha-
viour of unrelated code.
This commit solves those pitfalls by moving breakpoints into a global
breakpoint bitfield. Dbstate ops now have an extra field on the end
holding a sequence number, representing which bit holds the breakpoint
for that op.
Diffstat (limited to 'mg.c')
-rw-r--r-- | mg.c | 17 |
1 files changed, 6 insertions, 11 deletions
@@ -2002,19 +2002,14 @@ Perl_magic_setdbline(pTHX_ SV *sv, MAGIC *mg) sv_2iv(MUTABLE_SV((mg)->mg_ptr)), FALSE); if (svp && SvIOKp(*svp)) { - OP * const o = INT2PTR(OP*,SvIVX(*svp)); - if (o) { -#ifdef PERL_DEBUG_READONLY_OPS - Slab_to_rw(OpSLAB(o)); -#endif - /* set or clear breakpoint in the relevant control op */ + size_t off = SvUVX(*svp); + size_t sz = off+8/8; + if (sz <= PL_breakpointslen) { + /* set or clear breakpoint */ if (SvTRUE(sv)) - o->op_flags |= OPf_SPECIAL; + PL_breakpoints[off/8] |= 1 << off%8; else - o->op_flags &= ~OPf_SPECIAL; -#ifdef PERL_DEBUG_READONLY_OPS - Slab_to_ro(OpSLAB(o)); -#endif + PL_breakpoints[off/8] &= ~(U8)(1 << off%8); } } return 0; |