Fix croaking on "my $_" when "use utf8" is in effect

This commit is contained in:
Petr Písař 2021-02-09 18:55:35 +01:00
parent 9efe548119
commit a12f1b7585
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,78 @@
From 07319fdbb283f93cb655c3106b5237cbc7272038 Mon Sep 17 00:00:00 2001
From: Tomasz Konojacki <me@xenu.pl>
Date: Wed, 30 Dec 2020 14:03:02 +0100
Subject: [PATCH] op.c: croak on "my $_" when "use utf8" is in effect
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Fixes #18449
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
op.c | 16 +++++++++-------
t/op/mydef.t | 11 +++++++++--
2 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/op.c b/op.c
index b2e12dd0c0..dce844d297 100644
--- a/op.c
+++ b/op.c
@@ -730,6 +730,7 @@ PADOFFSET
Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags)
{
PADOFFSET off;
+ bool is_idfirst, is_default;
const bool is_our = (PL_parser->in_my == KEY_our);
PERL_ARGS_ASSERT_ALLOCMY;
@@ -738,14 +739,15 @@ Perl_allocmy(pTHX_ const char *const name, const STRLEN len, const U32 flags)
Perl_croak(aTHX_ "panic: allocmy illegal flag bits 0x%" UVxf,
(UV)flags);
+ is_idfirst = flags & SVf_UTF8
+ ? isIDFIRST_utf8_safe((U8*)name + 1, name + len)
+ : isIDFIRST_A(name[1]);
+
+ /* $_, @_, etc. */
+ is_default = len == 2 && name[1] == '_';
+
/* complain about "my $<special_var>" etc etc */
- if ( len
- && !( is_our
- || isALPHA(name[1])
- || ( (flags & SVf_UTF8)
- && isIDFIRST_utf8_safe((U8 *)name+1, name + len))
- || (name[1] == '_' && len > 2)))
- {
+ if (!is_our && (!is_idfirst || is_default)) {
const char * const type =
PL_parser->in_my == KEY_sigvar ? "subroutine signature" :
PL_parser->in_my == KEY_state ? "\"state\"" : "\"my\"";
diff --git a/t/op/mydef.t b/t/op/mydef.t
index 42a81d9ab0..225ce98e51 100644
--- a/t/op/mydef.t
+++ b/t/op/mydef.t
@@ -6,10 +6,17 @@ BEGIN {
set_up_inc('../lib');
}
-plan tests => 1;
-
use strict;
eval 'my $_';
like $@, qr/^Can't use global \$_ in "my" at /;
+{
+ # using utf8 allows $_ to be declared with 'my'
+ # GH #18449
+ use utf8;
+ eval 'my $_;';
+ like $@, qr/^Can't use global \$_ in "my" at /;
+}
+
+done_testing;
--
2.26.2

View File

@ -251,6 +251,10 @@ Patch49: perl-5.33.4-locale.c-Fix-typo-in-ifdef.patch
# Fix fc() in Turkish locale, in upstream after 5.33.5
Patch50: perl-5.33.5-Fix-buggy-fc-in-Turkish-locale.patch
# Fix croaking on "my $_" when "use utf8" is in effect, GH#18449,
# in upstream after 5.33.5
Patch51: perl-5.33.5-op.c-croak-on-my-_-when-use-utf8-is-in-effect.patch
# Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@ -4302,6 +4306,7 @@ you're not running VMS, this module does nothing.
%patch48 -p1
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch200 -p1
%patch201 -p1
@ -4351,6 +4356,7 @@ perl -x patchlevel.h \
'Fedora Patch48: Make accessing environment by DynaLoader thread-safe' \
'Fedora Patch49: Use duplocale() if available' \
'Fedora Patch50: Fix fc() in Turkish locale' \
'Fedora Patch51: Fix croaking on "my $_" when "use utf8" is in effect (GH#18449)' \
'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \
'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
%{nil}
@ -7082,6 +7088,7 @@ popd
- Make accessing environment by DynaLoader thread-safe
- Use duplocale() if available
- Fix fc() in Turkish locale
- Fix croaking on "my $_" when "use utf8" is in effect (GH#18449)
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 4:5.32.1-470
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild