diff options
author | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-26 05:32:02 +0000 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-06-26 05:32:02 +0000 |
commit | 504f80c1f3625809f472c1ce21089fdae860d9fd (patch) | |
tree | cfeaae7da4b08f0f27798122ecbf4f1efba3b8cb /perl.c | |
parent | 14180c03bf5269934b197b82e34fd4696ad1053d (diff) | |
download | perl-504f80c1f3625809f472c1ce21089fdae860d9fd.tar.gz |
Bite the bullet and apply the hash randomisation patch.
[perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0
p4raw-id: //depot/perl@19854
Diffstat (limited to 'perl.c')
-rw-r--r-- | perl.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -275,6 +275,33 @@ perl_construct(pTHXx) PL_stashcache = newHV(); +#if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT) + /* [perl #22371] Algorimic Complexity Attack on Perl 5.6.1, 5.8.0 */ + { + char *s = PerlEnv_getenv("PERL_HASH_SEED"); + if (s) + while (isSPACE(*s)) s++; + if (s && isDIGIT(*s)) + PL_hash_seed = (UV)atoi(s); +#ifndef USE_HASH_SEED_EXPLICIT + else { + /* Compute a random seed */ + (void)seedDrand01((Rand_seed_t)seed()); + PL_srand_called = TRUE; + PL_hash_seed = (UV)(Drand01() * (NV)UV_MAX); +#if RANDBITS < (UVSIZE * 8) + { + int skip = (UVSIZE * 8) - RANDBITS; + PL_hash_seed >>= skip; + /* The low bits might need extra help. */ + PL_hash_seed += (UV)(Drand01() * ((1 << skip) - 1)); + } +#endif /* RANDBITS < (UVSIZE * 8) */ + } +#endif /* USE_HASH_SEED_EXPLICIT */ + } +#endif /* #if defined(USE_HASH_SEED) || defined(USE_HASH_SEED_EXPLICIT) */ + ENTER; } |