This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix segfault in filehandle duplication
[perl5.git] / hv_func.h
index 28b07b9..b2bde90 100644 (file)
--- a/hv_func.h
+++ b/hv_func.h
@@ -11,9 +11,9 @@
 
 #ifndef PERL_SEEN_HV_FUNC_H /* compile once */
 #define PERL_SEEN_HV_FUNC_H
-#define PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
 
 #if !( 0 \
+        || defined(PERL_HASH_FUNC_SIPHASH) \
         || defined(PERL_HASH_FUNC_SDBM) \
         || defined(PERL_HASH_FUNC_DJB2) \
         || defined(PERL_HASH_FUNC_SUPERFAST) \
         || defined(PERL_HASH_FUNC_ONE_AT_A_TIME_HARD) \
         || defined(PERL_HASH_FUNC_ONE_AT_A_TIME_OLD) \
     )
-#ifdef HAS_QUAD
-#define PERL_HASH_FUNC_SIPHASH
-#else
 #define PERL_HASH_FUNC_ONE_AT_A_TIME_HARD
 #endif
-#endif
 
 #if defined(PERL_HASH_FUNC_SIPHASH)
 #   define PERL_HASH_FUNC "SIPHASH_2_4"
@@ -392,8 +388,8 @@ S_perl_hash_murmur3(const unsigned char * const seed, const unsigned char *ptr,
     /* This CPU does not handle unaligned word access */
 
     /* Consume enough so that the next data byte is word aligned */
-    int i = -(long)ptr & 3;
-    if(i && (STRLEN)i <= len) {
+    STRLEN i = -PTR2IV(ptr) & 3;
+    if(i && i <= len) {
       MURMUR_DOBYTES(i, h1, carry, bytes_in_carry, ptr, len);
     }
 
@@ -476,6 +472,16 @@ S_perl_hash_sdbm(const unsigned char * const seed, const unsigned char *str, con
     return hash;
 }
 
+/* - ONE_AT_A_TIME_HARD is the 5.17+ recommend ONE_AT_A_TIME algorithm
+ * - ONE_AT_A_TIME_OLD is the unmodified 5.16 and older algorithm
+ * - ONE_AT_A_TIME is a 5.17+ tweak of ONE_AT_A_TIME_OLD to
+ *   prevent strings of only \0 but different lengths from colliding
+ *
+ * Security-wise, from best to worst,
+ * ONE_AT_A_TIME_HARD > ONE_AT_A_TIME > ONE_AT_A_TIME_OLD
+ * There is a big drop-off in security between ONE_AT_A_TIME_HARD and
+ * ONE_AT_A_TIME
+ * */
 
 /* This is the "One-at-a-Time" algorithm by Bob Jenkins
  * from requirements by Colin Plumb.