summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-09-08 17:58:19 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-09-08 17:58:19 +0000
commite67b9e528630fa842f677b067da8b404fc3914ab (patch)
tree61e3c724e9f6d99a5e24ade80c16d99361aa2abb
parent6c8f3f7c9e7275f18dac56cdf0b9dc266f2e2190 (diff)
downloadperl-e67b9e528630fa842f677b067da8b404fc3914ab.tar.gz
Scott A. Crosby believes in not disclosing
any more information than necessary: therefore instead of hash_seed() we have now hashes_random(). p4raw-id: //depot/perl@21096
-rw-r--r--lib/Hash/Util.pm20
-rw-r--r--lib/Hash/Util.t4
-rw-r--r--pod/perlrun.pod12
-rw-r--r--universal.c8
4 files changed, 23 insertions, 21 deletions
diff --git a/lib/Hash/Util.pm b/lib/Hash/Util.pm
index 8e8c95265c..7c528a2f59 100644
--- a/lib/Hash/Util.pm
+++ b/lib/Hash/Util.pm
@@ -7,7 +7,7 @@ use Carp;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(lock_keys unlock_keys lock_value unlock_value
- lock_hash unlock_hash hash_seed
+ lock_hash unlock_hash hashes_random
);
our $VERSION = 0.05;
@@ -20,7 +20,7 @@ Hash::Util - A selection of general-utility hash subroutines
use Hash::Util qw(lock_keys unlock_keys
lock_value unlock_value
lock_hash unlock_hash
- hash_seed);
+ hashes_random);
%hash = (foo => 42, bar => 23);
lock_keys(%hash);
@@ -33,7 +33,7 @@ Hash::Util - A selection of general-utility hash subroutines
lock_hash (%hash);
unlock_hash(%hash);
- my $hashes_are_randomised = hash_seed() != 0;
+ my $hashes_random = hashes_random();
=head1 DESCRIPTION
@@ -179,18 +179,18 @@ sub unlock_hash (\%) {
}
-=item B<hash_seed>
+=item B<hashes_random>
- my $hash_seed = hash_seed();
+ my $hashes_random = hashes_random();
-hash_seed() returns the seed number used to randomise hash ordering.
-Zero means the "traditional" random hash ordering, non-zero means the
-new even more random hash ordering introduced in Perl 5.8.1.
+hashes_random() returns true if Perl hashes are randomised as in Perl
+5.8.1 and later, false if Perl hashes have a predictable order as in
+Perl 5.8.0 and earlier.
=cut
-sub hash_seed () {
- Internals::hash_seed();
+sub hashes_random () {
+ Internals::hashes_random();
}
=back
diff --git a/lib/Hash/Util.t b/lib/Hash/Util.t
index 7cffcbe47b..512f07c2e6 100644
--- a/lib/Hash/Util.t
+++ b/lib/Hash/Util.t
@@ -6,7 +6,7 @@ BEGIN {
chdir 't';
}
}
-use Test::More tests => 157;
+use Test::More tests => 155;
use strict;
my @Exported_Funcs;
@@ -274,5 +274,3 @@ like( $@, qr/^Attempt to access disallowed key 'I_DONT_EXIST' in a restricted ha
}
}
-my $hash_seed = hash_seed();
-ok($hash_seed >= 0, "hash_seed $hash_seed");
diff --git a/pod/perlrun.pod b/pod/perlrun.pod
index f8a0ae6be6..299cbf91ea 100644
--- a/pod/perlrun.pod
+++ b/pod/perlrun.pod
@@ -1140,13 +1140,17 @@ This means that each different run of Perl will have a different
ordering of the results of keys(), values(), and each().
See L<perlsec/"Algorithmic Complexity Attacks"> for more information,
-and also L</PERL_HASH_SEED>.
+and also L</PERL_HASH_SEED_DEBUG>.
=item PERL_HASH_SEED_DEBUG
-(Since Perl 5.8.1.) Set to "1" to display (to STDERR) the value of
-the hash seed at the beginning of execution.
-See also hash_seed() of L<Hash::Util>.
+(Since Perl 5.8.1.) Set to one to display (to STDERR) the value of
+the hash seed at the beginning of execution. B<Note that the hash
+seed is sensitive information>: by knowing it one can craft a
+denial-of-service attack against Perl code, even remotely, see
+L<perlsec/"Algorithmic Complexity Attacks"> for more information.
+B<Do not disclose the hash seed> to people who don't need to know it.
+See also hashes_random() of L<Hash::Util>.
=item PERL_ROOT (specific to the VMS port)
diff --git a/universal.c b/universal.c
index 15c408d301..dc9e253062 100644
--- a/universal.c
+++ b/universal.c
@@ -187,7 +187,7 @@ XS(XS_Internals_SvREFCNT);
XS(XS_Internals_hv_clear_placehold);
XS(XS_PerlIO_get_layers);
XS(XS_Regexp_DESTROY);
-XS(XS_Internals_hash_seed);
+XS(XS_Internals_hashes_random);
void
Perl_boot_core_UNIVERSAL(pTHX)
@@ -231,7 +231,7 @@ Perl_boot_core_UNIVERSAL(pTHX)
newXSproto("PerlIO::get_layers",
XS_PerlIO_get_layers, file, "*;@");
newXS("Regexp::DESTROY", XS_Regexp_DESTROY, file);
- newXSproto("Internals::hash_seed",XS_Internals_hash_seed, file, "");
+ newXSproto("Internals::hashes_random",XS_Internals_hashes_random, file, "");
}
@@ -908,9 +908,9 @@ XS(XS_PerlIO_get_layers)
XSRETURN(0);
}
-XS(XS_Internals_hash_seed)
+XS(XS_Internals_hashes_random)
{
dXSARGS;
- XSRETURN_UV(PL_hash_seed);
+ XSRETURN_IV(PL_hash_seed ? 1 : 0);
}