perl-unicode

[PATCH] bytes.pm doesn't check undefined subroutine calling

2005-05-26 07:46:23
A problem of bytes.pm was reported at perl-unicode list last month.
  cf. http://www.nntp.perl.org/group/perl.unicode/2803

The problem is that a infinite loop is invoked once an undefined
subroutine in bytes:: package is called.

Older AUTOLOAD subroutine in bytes.pm doesn't check
whether called subroutine is defined or not.
So goto() causes recursive AUTOLOAD calling inifinitely.

The following patch changes utf8.pm and utf8.t.

Regards,
SADAHIRO Tomoyuki


diff -ur perl~/lib/bytes.pm perl/lib/bytes.pm
--- perl~/lib/bytes.pm  Wed Sep 03 18:39:15 2003
+++ perl/lib/bytes.pm   Thu May 26 23:17:59 2005
@@ -1,6 +1,6 @@
 package bytes;
 
-our $VERSION = '1.01';
+our $VERSION = '1.02';
 
 $bytes::hint_bits = 0x00000008;
 
@@ -14,7 +14,9 @@
 
 sub AUTOLOAD {
     require "bytes_heavy.pl";
-    goto &$AUTOLOAD;
+    goto &$AUTOLOAD if defined &$AUTOLOAD;
+    require Carp;
+    Carp::croak("Undefined subroutine $AUTOLOAD called");
 }
 
 sub length ($);
diff -ur perl~/lib/bytes.t perl/lib/bytes.t
--- perl~/lib/bytes.t   Wed Sep 03 18:39:15 2003
+++ perl/lib/bytes.t    Wed May 25 23:09:10 2005
@@ -4,7 +4,7 @@
     require './test.pl';
 }
 
-plan tests => 19;
+plan tests => 20;
 
 my $a = chr(0x100);
 
@@ -45,4 +45,10 @@
     is(bytes::substr($c, 0, 1), "\xc4", "bytes::substr under use bytes looks 
at bytes");
     is(bytes::index($c, "\x80"), 1, "bytes::index under use bytes looks at 
bytes");
     is(bytes::rindex($c, "\xc4"), 0, "bytes::rindex under use bytes looks at 
bytes");
+}
+
+{
+    fresh_perl_like ('use bytes; bytes::moo()',
+                    qr/Undefined subroutine bytes::moo/, {stderr=>1},
+                   "Check Carp is loaded for AUTOLOADing errors")
 }
###END OF PATCH



<Prev in Thread] Current Thread [Next in Thread>
  • [PATCH] bytes.pm doesn't check undefined subroutine calling, SADAHIRO Tomoyuki <=