]> granicus.if.org Git - php/commitdiff
MFH: mhash algorithm parameter was modified when it was a zval, also update a test.
authorScott MacVicar <scottmac@php.net>
Thu, 18 Sep 2008 11:59:13 +0000 (11:59 +0000)
committerScott MacVicar <scottmac@php.net>
Thu, 18 Sep 2008 11:59:13 +0000 (11:59 +0000)
NEWS
ext/hash/hash.c
ext/hash/tests/mhash_001.phpt
ext/hash/tests/mhash_004.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index af4f41102ef3fb45268bb64f704c8610a486b28c..2b8a3267a3e6fa508a8a1f4363ac043650a9d802 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP                                                                        NEWS
 - Changed error level E_ERROR into E_WARNING in Soap extension methods 
   parameter validation. (Felipe)
 
+- Fixed bug causing the algorithm parameter of mhash() to be modified. (Scott)
+
 - Fixed bug #46106 (Memory leaks when using global statement). (Dmitry)
 - Fixed bug #46099 (Xsltprocessor::setProfiling - memory leak). (Felipe, Rob).
 - Fixed bug #46087 (DOMXPath - segfault on destruction of a cloned object).
index 6d7c33b035f91cfbb815ee505b3f48b6bc6ad419..ce333f2ed9101643464d0d2166fc65e49c0b2447 100644 (file)
@@ -626,20 +626,22 @@ static void mhash_init(INIT_FUNC_ARGS)
 
 PHP_FUNCTION(mhash)
 {
-       zval *z_algorithm;
-       int algorithm;
+       zval **z_algorithm;
+       long algorithm;
 
-       if (zend_parse_parameters(1 TSRMLS_CC, "z", &z_algorithm) == FAILURE) {
+       if (zend_parse_parameters(1 TSRMLS_CC, "Z", &z_algorithm) == FAILURE) {
                return;
        }
 
-       algorithm = Z_LVAL_P(z_algorithm);
+       SEPARATE_ZVAL(z_algorithm);
+       convert_to_long_ex(z_algorithm);
+       algorithm = Z_LVAL_PP(z_algorithm);
 
        /* need to conver the first parameter from int to string */
        if (algorithm >= 0 && algorithm < MHASH_NUM_ALGOS) {
                struct mhash_bc_entry algorithm_lookup = mhash_to_hash[algorithm];
                if (algorithm_lookup.hash_name) {
-                       ZVAL_STRING(z_algorithm, algorithm_lookup.hash_name, 1);
+                       ZVAL_STRING(*z_algorithm, algorithm_lookup.hash_name, 1);
                }
        }
 
index 2d40e68d64756ecf44f9c93ebd2611aa2b2f9bef..f70ebaf8ff642d5d98a36048d2d578370e825e59 100644 (file)
@@ -33,7 +33,7 @@ foreach ($supported_hash_al as $hash=>$wanted) {
                echo "$hash: ";
                var_dump($wanted);
                echo "$hash: ";
-               var_dump($result);
+               var_dump(bin2hex($result));
        }
        echo "\n";
 }
diff --git a/ext/hash/tests/mhash_004.phpt b/ext/hash/tests/mhash_004.phpt
new file mode 100644 (file)
index 0000000..2721663
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+mhash() modifying algorithm parameter
+--INI--
+magic_quotes_runtime=0
+--SKIPIF--
+<?php
+       include "skip_mhash.inc";
+?>
+--FILE--
+<?php
+
+$algo = MHASH_MD5;
+var_dump($algo);
+var_dump(bin2hex(mhash($algo, "test")));
+var_dump($algo);
+
+?>
+--EXPECT--
+int(1)
+string(32) "098f6bcd4621d373cade4e832627b4f6"
+int(1)