diff options
author | Yves Orton <demerphq@gmail.com> | 2013-03-17 20:19:09 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2013-03-19 00:23:11 +0100 |
commit | 0e0ab62106f892a1b7f00ad117493064bf9d72d1 (patch) | |
tree | fdd83225227f4b59da3cb0fbb7e21e702f515e56 /embed.h | |
parent | b716320d9d4e3483bbddcbf6c6977a2a6a0efa1e (diff) | |
download | perl-0e0ab62106f892a1b7f00ad117493064bf9d72d1.tar.gz |
Harden hashes against hash seed discovery by randomizing hash iteration
Adds:
S_ptr_hash() - A new static function in hv.c which can be used to
hash a pointer or integer.
PL_hash_rand_bits - A new interpreter variable used as a cheap
provider of "semi-random" state for use by the hash infrastructure.
xpvhv_aux.xhv_rand - Used as a mask which is xored against the
xpvhv_aux.riter during iteration to randomize the order the actual
buckets are visited.
PL_hash_rand_bits is initialized as interpreter start from the random
hash seed, and then modified by "mixing in" the result of ptr_hash()
on the bucket array pointer in the hv (HvARRAY(hv)) every time
hv_auxinit() allocates a new iterator structure.
The net result is that every hash has its own iteration order, which
should make it much more difficult to determine what the current hash
seed is.
This required some test to be restructured, as they tested for something
that was not necessarily true, we never guaranteed that two hashes with
the same keys would produce the same key order, we merely promised that
using keys(), values(), or each() on the same hash, without any
insertions in between, would produce the same order of visiting the
key/values.
Diffstat (limited to 'embed.h')
-rw-r--r-- | embed.h | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -1376,12 +1376,13 @@ #define clear_placeholders(a,b) S_clear_placeholders(aTHX_ a,b) #define hfreeentries(a) S_hfreeentries(aTHX_ a) #define hsplit(a,b,c) S_hsplit(aTHX_ a,b,c) -#define hv_auxinit S_hv_auxinit +#define hv_auxinit(a) S_hv_auxinit(aTHX_ a) #define hv_delete_common(a,b,c,d,e,f,g) S_hv_delete_common(aTHX_ a,b,c,d,e,f,g) #define hv_free_ent_ret(a,b) S_hv_free_ent_ret(aTHX_ a,b) #define hv_magic_check S_hv_magic_check #define hv_notallowed(a,b,c,d) S_hv_notallowed(aTHX_ a,b,c,d) #define new_he() S_new_he(aTHX) +#define ptr_hash S_ptr_hash #define refcounted_he_value(a) S_refcounted_he_value(aTHX_ a) #define save_hek_flags S_save_hek_flags #define share_hek_flags(a,b,c,d) S_share_hek_flags(aTHX_ a,b,c,d) |