Fix panic when encoding undefined scalars

This commit is contained in:
Petr Písař 2016-09-30 11:03:18 +02:00
parent e02bca8997
commit 927bd09f43
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,47 @@
From 519fb7e761447245fed9bb2de02e894b71ccae2f Mon Sep 17 00:00:00 2001
From: Vincent van Dam <vvandam@sandvine.com>
Date: Thu, 22 Sep 2016 14:48:05 +0200
Subject: [PATCH] Fix panic when encoding undef scalars
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
lib/Encode/Encoder.pm | 4 +++-
t/undef.t | 8 ++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 t/undef.t
diff --git a/lib/Encode/Encoder.pm b/lib/Encode/Encoder.pm
index 23e0349..fef4e9b 100644
--- a/lib/Encode/Encoder.pm
+++ b/lib/Encode/Encoder.pm
@@ -85,7 +85,9 @@ sub AUTOLOAD {
from_to( $self->{data}, $self->{encoding}, $obj->name, 1 );
}
else {
- $self->{data} = $obj->encode( $self->{data}, 1 );
+ if ( defined($self->{data}) ) {
+ $self->{data} = $obj->encode( $self->{data}, 1 );
+ }
}
$self->{encoding} = $obj->name;
return $self;
diff --git a/t/undef.t b/t/undef.t
new file mode 100644
index 0000000..ad8bcd6
--- /dev/null
+++ b/t/undef.t
@@ -0,0 +1,8 @@
+use Encode::Encoder qw(encoder);
+
+use Test::More;
+plan tests => 1;
+
+my $emptyutf8;
+eval { $c = encoder($emptyutf8)->utf8; };
+ok(!$@,"crashed encoding undef variable ($@)");
--
2.7.4

View File

@ -32,6 +32,9 @@ Patch3: Encode-2.86-Encode-utf8-Check-for-overflowed-and-overlong-UTF-8-
# 3/3 Refusing non-shortests UTF-8 representations,
# <https://github.com/dankogai/p5-encode/issues/64>, in upstream after 2.86
Patch4: Encode-2.86-Encode-utf8-Fix-count-of-replacement-characters-for-.patch
# Fix panic when encoding undefined scalars,
# <https://github.com/dankogai/p5-encode/pull/66>, in upstream after 2.86
Patch5: Encode-2.86-Fix-panic-when-encoding-undef-scalars.patch
BuildRequires: coreutils
BuildRequires: findutils
BuildRequires: make
@ -147,6 +150,7 @@ your own encoding to perl. No knowledge of XS is necessary.
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%build
# Additional scripts can be installed by appending MORE_SCRIPTS, UCM files by
@ -191,6 +195,7 @@ make test
* Fri Sep 30 2016 Petr Pisar <ppisar@redhat.com> - 4:2.86-3
- Fix Encode::encode_utf8(undef) to return undef (CPAN RT#116904)
- Refuse non-shortests UTF-8 representations in strict mode
- Fix panic when encoding undefined scalars
* Fri Sep 16 2016 Petr Pisar <ppisar@redhat.com> - 4:2.86-2
- Add Artistic 2.0 into license tag because of encguess tool