summaryrefslogtreecommitdiff
path: root/proto.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2013-03-17 20:19:09 +0100
committerYves Orton <demerphq@gmail.com>2013-03-19 00:23:11 +0100
commit0e0ab62106f892a1b7f00ad117493064bf9d72d1 (patch)
treefdd83225227f4b59da3cb0fbb7e21e702f515e56 /proto.h
parentb716320d9d4e3483bbddcbf6c6977a2a6a0efa1e (diff)
downloadperl-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 'proto.h')
-rw-r--r--proto.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/proto.h b/proto.h
index 35d49db3d6..3d546a0fdf 100644
--- a/proto.h
+++ b/proto.h
@@ -5706,8 +5706,8 @@ STATIC void S_hsplit(pTHX_ HV *hv, STRLEN const oldsize, STRLEN newsize)
#define PERL_ARGS_ASSERT_HSPLIT \
assert(hv)
-STATIC struct xpvhv_aux* S_hv_auxinit(HV *hv)
- __attribute__nonnull__(1);
+STATIC struct xpvhv_aux* S_hv_auxinit(pTHX_ HV *hv)
+ __attribute__nonnull__(pTHX_1);
#define PERL_ARGS_ASSERT_HV_AUXINIT \
assert(hv)
@@ -5736,6 +5736,7 @@ STATIC HE* S_new_he(pTHX)
__attribute__malloc__
__attribute__warn_unused_result__;
+STATIC U32 S_ptr_hash(PTRV u);
STATIC SV * S_refcounted_he_value(pTHX_ const struct refcounted_he *he)
__attribute__nonnull__(pTHX_1);
#define PERL_ARGS_ASSERT_REFCOUNTED_HE_VALUE \