This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
tighten Storable's recognition of tied SVs
[perl5.git] / dist / Storable / Storable.pm
index 561f00e..f74c867 100644 (file)
@@ -1,5 +1,6 @@
 #
-#  Copyright (c) 1995-2000, Raphael Manfredi
+#  Copyright (c) 1995-2001, Raphael Manfredi
+#  Copyright (c) 2002-2013 by the Perl 5 Porters
 #  
 #  You may redistribute only under the same terms as Perl 5, as specified
 #  in the README file that comes with the distribution.
@@ -21,7 +22,7 @@ package Storable; @ISA = qw(Exporter);
 
 use vars qw($canonical $forgive_me $VERSION);
 
-$VERSION = '2.33';
+$VERSION = '2.49';
 
 BEGIN {
     if (eval { local $SIG{__DIE__}; require Log::Agent; 1 }) {
@@ -31,13 +32,13 @@ BEGIN {
     # Use of Log::Agent is optional. If it hasn't imported these subs then
     # provide a fallback implementation.
     #
-    if (!exists &logcroak) {
+    unless ($Storable::{logcroak} && *{$Storable::{logcroak}}{CODE}) {
         require Carp;
         *logcroak = sub {
             Carp::croak(@_);
         };
     }
-    if (!exists &logcarp) {
+    unless ($Storable::{logcarp} && *{$Storable::{logcarp}}{CODE}) {
        require Carp;
         *logcarp = sub {
           Carp::carp(@_);
@@ -311,7 +312,7 @@ sub _store_fd {
 #
 # freeze
 #
-# Store oject and its hierarchy in memory and return a scalar
+# Store object and its hierarchy in memory and return a scalar
 # containing the result.
 #
 sub freeze {
@@ -905,8 +906,8 @@ This returns the file format version as number.  It is a string like
 "2.007".  This value is suitable for numeric comparisons.
 
 The constant function C<Storable::BIN_VERSION_NV> returns a comparable
-number that represent the highest file version number that this
-version of Storable fully support (but see discussion of
+number that represents the highest file version number that this
+version of Storable fully supports (but see discussion of
 C<$Storable::accept_future_minor> above).  The constant
 C<Storable::BIN_WRITE_VERSION_NV> function returns what file version
 is written and might be less than C<Storable::BIN_VERSION_NV> in some
@@ -1019,6 +1020,38 @@ compartment:
 =for example_testing
         is( $code->(), 42 );
 
+=head1 SECURITY WARNING
+
+B<Do not accept Storable documents from untrusted sources!>
+
+Some features of Storable can lead to security vulnerabilities if you
+accept Storable documents from untrusted sources. Most obviously, the
+optional (off by default) CODE reference serialization feature allows
+transfer of code to the deserializing process. Furthermore, any
+serialized object will cause Storable to helpfully load the module
+corresponding to the class of the object in the deserializing module.
+For manipulated module names, this can load almost arbitrary code.
+Finally, the deserialized object's destructors will be invoked when
+the objects get destroyed in the deserializing process. Maliciously
+crafted Storable documents may put such objects in the value of
+a hash key that is overridden by another key/value pair in the
+same hash, thus causing immediate destructor execution.
+
+In a future version of Storable, we intend to provide options to disable
+loading modules for classes and to disable deserializing objects
+altogether. I<Nonetheless, Storable deserializing documents from
+untrusted sources is expected to have other, yet undiscovered,
+security concerns such as allowing an attacker to cause the deserializer
+to crash hard.>
+
+B<Therefore, let me repeat: Do not accept Storable documents from
+untrusted sources!>
+
+If your application requires accepting data from untrusted sources, you
+are best off with a less powerful and more-likely safe serialization format
+and implementation. If your data is sufficiently simple, JSON is a good
+choice and offers maximum interoperability.
+
 =head1 WARNING
 
 If you're using references as keys within your hash tables, you're bound
@@ -1130,7 +1163,7 @@ correct behaviour.
 What this means is that if you have data written by Storable 1.x running
 on perl 5.6.0 or 5.6.1 configured with 64 bit integers on Unix or Linux
 then by default this Storable will refuse to read it, giving the error
-I<Byte order is not compatible>.  If you have such data then you you
+I<Byte order is not compatible>.  If you have such data then you
 should set C<$Storable::interwork_56_64bit> to a true value to make this
 Storable read and write files with the old header.  You should also
 migrate your data, or any older perl you are communicating with, to this
@@ -1160,7 +1193,8 @@ Thank you to (in chronological order):
        Salvador Ortiz Garcia <sog@msg.com.mx>
        Dominic Dunlop <domo@computer.org>
        Erik Haugan <erik@solbors.no>
-    Benjamin A. Holzman <ben.holzman@grantstreet.com>
+       Benjamin A. Holzman <ben.holzman@grantstreet.com>
+       Reini Urban <rurban@cpanel.net>
 
 for their bug reports, suggestions and contributions.