]> granicus.if.org Git - php/commitdiff
We can't stay zend_string->h to be zero, because it may lead to hash value recalculat...
authorDmitry Stogov <dmitry@zend.com>
Tue, 24 Mar 2015 13:28:26 +0000 (16:28 +0300)
committerDmitry Stogov <dmitry@zend.com>
Tue, 24 Mar 2015 13:28:26 +0000 (16:28 +0300)
But in general zend_string may be put and read-only memory, that would lead to crash.
Always set the high bit of hash_value to prevent recaclulation.

Zend/zend_string.h

index 29985b73356e1760052b2a237ad4b0ae858f1aa5..97528a71f34a70b48ccadb2b5dc0e5f6da9d582f 100644 (file)
@@ -324,7 +324,14 @@ static zend_always_inline zend_ulong zend_inline_hash_func(const char *str, size
 EMPTY_SWITCH_DEFAULT_CASE()
        }
 
-       return hash;
+       /* Hash value can't be zero, so we always set the high bit */
+#if SIZEOF_ZEND_LONG == 8
+       return hash | Z_UL(0x8000000000000000);
+#elif SIZEOF_ZEND_LONG == 4
+       return hash | Z_UL(0x80000000);
+#else
+# error "Unknown SIZEOF_ZEND_LONG"
+#endif
 }
 
 static zend_always_inline void zend_interned_empty_string_init(zend_string **s)