summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-07-11 00:03:33 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-07-11 00:03:33 +0000
commitbed601927f5ca7f54b544d9e5ce1f77461311b68 (patch)
tree76f5d01619419491feebf3cfa159cb51489543cd /util.c
parent183c3da10ba46f0626790e1aa75f641397137480 (diff)
downloadperl-bed601927f5ca7f54b544d9e5ce1f77461311b68.tar.gz
Chicken out: the hash randomisation is not on by default.
We switch over to the explicit mode: in other words, if the $ENV{PERL_HASH_SEED} is on, we randomise. Also, we randomise only if PL_hash_seed_set is FALSE (this means one can use PERL_HASH() before perl_run.) Also, since now PERL_HASH_SEED is okay even under -T, all should be fine. (Ha!) p4raw-id: //depot/perl@20135
Diffstat (limited to 'util.c')
-rw-r--r--util.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/util.c b/util.c
index 80af15519f..4f53a91417 100644
--- a/util.c
+++ b/util.c
@@ -4377,3 +4377,35 @@ Perl_seed(pTHX)
return u;
}
+UV
+Perl_get_seed(void)
+{
+ char *s = PerlEnv_getenv("PERL_HASH_SEED");
+ UV myseed = 0;
+
+ if (s)
+ while (isSPACE(*s)) s++;
+ if (s && isDIGIT(*s))
+ myseed = (UV)Atoul(s);
+ else
+#ifdef USE_HASH_SEED_EXPLICIT
+ if (s)
+#endif
+ {
+ /* Compute a random seed */
+ (void)seedDrand01((Rand_seed_t)seed());
+ PL_srand_called = TRUE;
+ myseed = (UV)(Drand01() * (NV)UV_MAX);
+#if RANDBITS < (UVSIZE * 8)
+ /* Since there are not enough randbits to to reach all
+ * the bits of a UV, the low bits might need extra
+ * help. Sum in another random number that will
+ * fill in the low bits. */
+ myseed +=
+ (UV)(Drand01() * (NV)((1 << ((UVSIZE * 8 - RANDBITS))) - 1));
+#endif /* RANDBITS < (UVSIZE * 8) */
+ }
+ PL_hash_seed_set = TRUE;
+
+ return myseed;
+}