From 49968c41a44273d5bf22abf3dc464b8bbc7853fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 12 Nov 2020 14:54:17 +0100 Subject: [PATCH] Fix un undefined behavior in Perl_custom_op_get_field() --- ..._op_get_field-remove-undef-behaviour.patch | 76 +++++++++++++++++++ perl.spec | 11 ++- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 perl-5.33.3-Perl_custom_op_get_field-remove-undef-behaviour.patch diff --git a/perl-5.33.3-Perl_custom_op_get_field-remove-undef-behaviour.patch b/perl-5.33.3-Perl_custom_op_get_field-remove-undef-behaviour.patch new file mode 100644 index 0000000..24528d3 --- /dev/null +++ b/perl-5.33.3-Perl_custom_op_get_field-remove-undef-behaviour.patch @@ -0,0 +1,76 @@ +From e050064b67c501e9fdc7bc3f513ba2b8b9e795f8 Mon Sep 17 00:00:00 2001 +From: David Mitchell +Date: Fri, 30 Oct 2020 20:50:58 +0000 +Subject: [PATCH] Perl_custom_op_get_field(): remove undef behaviour +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Thus function has a couple a switches with + + default: + NOT_REACHED; /* NOTREACHED */ + +but clang is complaining that the value returned by the function is +undefined if those default branches are taken, since the 'any' variable +doesn't get set in that path. + +Replace the NOTREACHED with a croak("panic: ..."). It's possible (albeit +not intended) for Perl_custom_op_get_field() to be called with a 'field' +arg which triggers the default case. So if this ever happens, make it +clear that something has gone wrong, rather than just silently +continuing on non-debugging builds. + +In any case, this shuts up clang. + +Signed-off-by: Petr Písař +--- + op.c | 14 ++++++-------- + 1 file changed, 6 insertions(+), 8 deletions(-) + +diff --git a/op.c b/op.c +index c30c6b7c8f..2933e2ed7d 100644 +--- a/op.c ++++ b/op.c +@@ -18100,6 +18100,7 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) + else + xop = INT2PTR(XOP *, SvIV(HeVAL(he))); + } ++ + { + XOPRETANY any; + if(field == XOPe_xop_ptr) { +@@ -18121,7 +18122,10 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) + any.xop_peep = xop->xop_peep; + break; + default: +- NOT_REACHED; /* NOTREACHED */ ++ field_panic: ++ Perl_croak(aTHX_ ++ "panic: custom_op_get_field(): invalid field %d\n", ++ (int)field); + break; + } + } else { +@@ -18139,17 +18143,11 @@ Perl_custom_op_get_field(pTHX_ const OP *o, const xop_flags_enum field) + any.xop_peep = XOPd_xop_peep; + break; + default: +- NOT_REACHED; /* NOTREACHED */ ++ goto field_panic; + break; + } + } + } +- /* On some platforms (HP-UX, IA64) gcc emits a warning for this function: +- * op.c: In function 'Perl_custom_op_get_field': +- * op.c:...: warning: 'any.xop_name' may be used uninitialized in this function [-Wmaybe-uninitialized] +- * This is because on those platforms (with -DEBUGGING) NOT_REACHED +- * expands to assert(0), which expands to ((0) ? (void)0 : +- * __assert(...)), and gcc doesn't know that __assert can never return. */ + return any; + } + } +-- +2.25.4 + diff --git a/perl.spec b/perl.spec index 83b2cd6..db0a0fa 100644 --- a/perl.spec +++ b/perl.spec @@ -100,7 +100,7 @@ License: GPL+ or Artistic Epoch: %{perl_epoch} Version: %{perl_version} # release number must be even higher, because dual-lived modules will be broken otherwise -Release: 465%{?dist} +Release: 466%{?dist} Summary: Practical Extraction and Report Language Url: https://www.perl.org/ Source0: https://www.cpan.org/src/5.0/perl-%{perl_version}.tar.xz @@ -255,6 +255,10 @@ Patch39: perl-5.33.2-mro.xs-Fix-compiler-warning.patch # Fix a code flow in Perl_sv_inc_nomg(), in upstream after 5.33.2 Patch40: perl-5.33.2-sv.c-Added-missing-braces-in-Perl_sv_inc_nomg.patch +# Fix un undefined behavior in Perl_custom_op_get_field(), +# in upstream after 5.33.3 +Patch41: perl-5.33.3-Perl_custom_op_get_field-remove-undef-behaviour.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 @@ -4297,6 +4301,7 @@ you're not running VMS, this module does nothing. %patch38 -p1 %patch39 -p1 %patch40 -p1 +%patch41 -p1 %patch200 -p1 %patch201 -p1 @@ -4344,6 +4349,7 @@ perl -x patchlevel.h \ 'Fedora Patch38: Fix sv_collxfrm macro to respect locale' \ 'Fedora Patch39: Fix an iterator signedness in handling a mro exception (GH#18155)' \ 'Fedora Patch40: Fix a code flow in Perl_sv_inc_nomg()' \ + 'Fedora Patch41: Fix un undefined behavior in Perl_custom_op_get_field()' \ '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} @@ -7062,6 +7068,9 @@ popd # Old changelog entries are preserved in CVS. %changelog +* Thu Nov 12 2020 Petr Pisar - 4:5.32.0-466 +- Fix un undefined behavior in Perl_custom_op_get_field() + * Wed Oct 14 2020 Petr Pisar - 4:5.32.0-465 - Fix sv_collxfrm macro to respect locale - Fix an iterator signedness in handling a mro exception (GH#18155)