Skip to content

Commit 1311cfc

Browse files
author
Father Chrysostomos
committed
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.
1 parent c82ecf3 commit 1311cfc

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

cop.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,8 @@ struct cop {
429429
#define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : NULL)
430430
#define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : NULL)
431431
#define CopFILEAVx(c) (assert_(CopFILEGV(c)) GvAV(CopFILEGV(c)))
432-
#define CopFILE(c) (CopFILEGV(c) && GvSV(CopFILEGV(c)) \
433-
? SvPVX(GvSV(CopFILEGV(c))) : NULL)
432+
#define CopFILE(c) (CopFILEGV(c) \
433+
? GvNAME(CopFILEGV(c))+2 : NULL)
434434
#define CopSTASHPV(c) (CopSTASH(c) ? HvNAME_get(CopSTASH(c)) : NULL)
435435
/* cop_stash is not refcounted */
436436
#define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD))

t/comp/parser.t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ BEGIN {
88
chdir 't';
99
}
1010

11-
print "1..157\n";
11+
print "1..158\n";
1212

1313
sub failed {
1414
my ($got, $expected, $name) = @_;
@@ -482,6 +482,11 @@ for(__PACKAGE__) {
482482
is $_, 'main', '__PACKAGE__ is read-only';
483483
}
484484
485+
$file = __FILE__;
486+
BEGIN{ ${"_<".__FILE__} = \1 }
487+
is __FILE__, $file,
488+
'no __FILE__ corruption when setting CopFILESV to a ref';
489+
485490
# Add new tests HERE (above this line)
486491
487492
# bug #74022: Loop on characters in \p{OtherIDContinue}

0 commit comments

Comments
 (0)