From 8ee4a8fd7c9508e43f402dc641ef5bb85670c84e Mon Sep 17 00:00:00 2001 From: Scott MacVicar Date: Thu, 18 Sep 2008 11:52:12 +0000 Subject: [PATCH] mhash algorithm parameter was modified when it was a zval, also update a test. --- ext/hash/hash.c | 12 +++++++----- ext/hash/tests/mhash_001.phpt | 2 +- ext/hash/tests/mhash_004.phpt | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 ext/hash/tests/mhash_004.phpt diff --git a/ext/hash/hash.c b/ext/hash/hash.c index f697badb31..54baadc20e 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -797,20 +797,22 @@ static void mhash_init(INIT_FUNC_ARGS) Hash data with hash */ 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); } } diff --git a/ext/hash/tests/mhash_001.phpt b/ext/hash/tests/mhash_001.phpt index 2d40e68d64..f70ebaf8ff 100644 --- a/ext/hash/tests/mhash_001.phpt +++ b/ext/hash/tests/mhash_001.phpt @@ -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 index 0000000000..a9f18034f9 --- /dev/null +++ b/ext/hash/tests/mhash_004.phpt @@ -0,0 +1,21 @@ +--TEST-- +mhash() modifying algorithm parameter +--INI-- +magic_quotes_runtime=0 +--SKIPIF-- + +--FILE-- + +--EXPECT-- +int(1) +unicode(32) "098f6bcd4621d373cade4e832627b4f6" +int(1) -- 2.40.0