From 1311cfc0a7b1bfcfd292948a7d88f0536e2e1c6e Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Sun, 4 Aug 2013 23:52:20 -0700 Subject: [PATCH] Prevent __FILE__ corruption when ${"_<..."} is modified This fixes a longstanding bug under non-threaded builds that was extended to threaded builds by the previous commit. Modifying the SV slot of the file gv can cause CopFILE to violate memory discipline, giving random strings. Since the GV is named after the file, too, and since its name can- not be changed from Perl space, use that for CopFILE instead. --- cop.h | 4 ++-- t/comp/parser.t | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cop.h b/cop.h index cfa976f..3deb2f8 100644 --- a/cop.h +++ b/cop.h @@ -429,8 +429,8 @@ struct cop { #define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL) #define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL) #define CopFILEAVx(c) (assert_(CopFILEGV(c)) GvAV(CopFILEGV(c))) -#define CopFILE(c) (CopFILEGV(c) && GvSV(CopFILEGV(c)) \ - ? SvPVX(GvSV(CopFILEGV(c))) : NULL) +#define CopFILE(c) (CopFILEGV(c) \ + ? GvNAME(CopFILEGV(c))+2 : NULL) #define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL) /* cop_stash is not refcounted */ #define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) diff --git a/t/comp/parser.t b/t/comp/parser.t index 5f0d407..a9b044a 100644 --- a/t/comp/parser.t +++ b/t/comp/parser.t @@ -8,7 +8,7 @@ BEGIN { chdir 't'; } -print "1..157\n"; +print "1..158\n"; sub failed { my ($got, $expected, $name) = @_; @@ -482,6 +482,11 @@ for(__PACKAGE__) { is $_, 'main', '__PACKAGE__ is read-only'; } +$file = __FILE__; +BEGIN{ ${"_<".__FILE__} = \1 } +is __FILE__, $file, + 'no __FILE__ corruption when setting CopFILESV to a ref'; + # Add new tests HERE (above this line) # bug #74022: Loop on characters in \p{OtherIDContinue} -- 2.7.4