-
Notifications
You must be signed in to change notification settings - Fork 540
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
double free and segfault in Perl v5.23.4-81-g96524c2 #15039
Comments
From @geeknikThe following triggers a double free (I think) and a segfault in Perl v5.23.4-81-g96524c2: perl -e 's//*_=0;s|0||;00.y0/e' ==6727== Invalid read of size 1 Program received signal SIGSEGV, Segmentation fault. |
From @dcollinsnThis is probably a stack-is-not-refcounted issue. The outer s/// places $_ On Mon, Nov 9, 2015 at 3:13 PM, Brian Carpenter <perlbug-followup@perl.org>
|
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Mon Nov 09 12:20:11 2015, dcollinsn@gmail.com wrote:
In this case the SV that's being freed isn't being stored on the argument stack, but on the context stack, and we can keep a reference count there. Patch with fix attached for review. Tony |
From @tonycoz0001-perl-126602-make-sure-targ-isn-t-freed-from-under-us.patchFrom 7a2d29de9695586d39befe1c5e32ac94642db5cf Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 11 Nov 2015 11:29:03 +1100
Subject: [perl #126602] make sure targ isn't freed from under us
---
cop.h | 6 ++++--
t/re/subst.t | 7 ++++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/cop.h b/cop.h
index d36d189..b15ddf4 100644
--- a/cop.h
+++ b/cop.h
@@ -939,11 +939,13 @@ struct subst {
cx->sb_rx = rx, \
cx->cx_type = CXt_SUBST | (once ? CXp_ONCE : 0); \
rxres_save(&cx->sb_rxres, rx); \
- (void)ReREFCNT_inc(rx)
+ (void)ReREFCNT_inc(rx); \
+ SvREFCNT_inc_void_NN(targ)
# define POPSUBST(cx) cx = &cxstack[cxstack_ix--]; \
rxres_free(&cx->sb_rxres); \
- ReREFCNT_dec(cx->sb_rx)
+ ReREFCNT_dec(cx->sb_rx); \
+ SvREFCNT_dec_NN(cx->sb_targ)
#endif
#define CxONCE(cx) ((cx)->cx_type & CXp_ONCE)
diff --git a/t/re/subst.t b/t/re/subst.t
index 2fed182..7939fe5 100644
--- a/t/re/subst.t
+++ b/t/re/subst.t
@@ -9,7 +9,7 @@ BEGIN {
require './loc_tools.pl';
}
-plan( tests => 267 );
+plan( tests => 268 );
$_ = 'david';
$a = s/david/rules/r;
@@ -1078,3 +1078,8 @@ SKIP: {
$s1 =~ s/.?/$s1++/ge;
is($s1, "01","RT #123954 s1");
}
+{
+ # RT #126602 double free if the value being modified is freed in the replacement
+ fresh_perl_is('s//*_=0;s|0||;00.y0/e; print qq(ok\n)', "ok\n", { stderr => 1 },
+ "[perl #126602] s//*_=0;s|0||/e crashes");
+}
--
2.1.4
|
From @tonycozOn Tue Nov 10 16:30:56 2015, tonyc wrote:
Applied in cf69025. Tony |
@tonycoz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#126602 (status was 'resolved')
Searchable as RT126602$
The text was updated successfully, but these errors were encountered: