andrey Tue, 14 Sep 2010 16:09:42 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=303366
Log: unify magic quotes handling. Also fix a problem which resulted in a longjmp in debug PHP,because of usage of zval that is NULL in a hash context. Changed paths: U php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c U php/php-src/branches/PHP_5_3/ext/mysqli/tests/mysqli_magic_quotes.phpt
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c 2010-09-14 15:33:43 UTC (rev 303365) +++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli.c 2010-09-14 16:09:42 UTC (rev 303366) @@ -1092,6 +1092,7 @@ MYSQL_FIELD *fields; MYSQL_ROW row; unsigned long *field_len; + zend_bool magic_quotes_warning_sent = FALSE; #endif if (into_object) { @@ -1175,7 +1176,10 @@ /* check if we need magic quotes */ if (PG(magic_quotes_runtime)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3"); + if (magic_quotes_warning_sent == FALSE) { + magic_quotes_warning_sent = TRUE; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3"); + } Z_TYPE_P(res) = IS_STRING; Z_STRVAL_P(res) = php_addslashes(row[i], field_len[i], &Z_STRLEN_P(res), 0 TSRMLS_CC); } else { @@ -1209,37 +1213,39 @@ char * string_key; uint string_key_len; ulong num_key; - php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3"); - array_init(return_value); - mysqlnd_fetch_into(result, ((fetchtype & MYSQLI_NUM)? MYSQLND_FETCH_NUM:0) | ((fetchtype & MYSQLI_ASSOC)? MYSQLND_FETCH_ASSOC:0), &new_return_value, MYSQLND_MYSQLI); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL(new_return_value), &pos_values); - while (zend_hash_get_current_data_ex(Z_ARRVAL(new_return_value), (void **)&entry_values, &pos_values) == SUCCESS) { - if (Z_TYPE_PP(entry_values) == IS_STRING) { - int new_str_len; - char * new_str = php_addslashes(Z_STRVAL_PP(entry_values), Z_STRLEN_PP(entry_values), &new_str_len, 0 TSRMLS_CC); - switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) { - case HASH_KEY_IS_LONG: - add_index_stringl(return_value, num_key, new_str, new_str_len, 0); - break; - case HASH_KEY_IS_STRING: - add_assoc_stringl_ex(return_value, string_key, string_key_len, new_str, new_str_len, 0); - break; + if (Z_TYPE(new_return_value) == IS_ARRAY) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "magic_quotes_runtime are deprecated since PHP 5.3"); + array_init(return_value); + zend_hash_internal_pointer_reset_ex(Z_ARRVAL(new_return_value), &pos_values); + while (zend_hash_get_current_data_ex(Z_ARRVAL(new_return_value), (void **)&entry_values, &pos_values) == SUCCESS) { + if (Z_TYPE_PP(entry_values) == IS_STRING) { + int new_str_len; + char * new_str = php_addslashes(Z_STRVAL_PP(entry_values), Z_STRLEN_PP(entry_values), &new_str_len, 0 TSRMLS_CC); + switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) { + case HASH_KEY_IS_LONG: + add_index_stringl(return_value, num_key, new_str, new_str_len, 0); + break; + case HASH_KEY_IS_STRING: + add_assoc_stringl_ex(return_value, string_key, string_key_len, new_str, new_str_len, 0); + break; + } + } else { + zval_add_ref(entry_values); + switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) { + case HASH_KEY_IS_LONG: + add_index_zval(return_value, num_key, *entry_values); + break; + case HASH_KEY_IS_STRING: + add_assoc_zval_ex(return_value, string_key, string_key_len, *entry_values); + break; + } } - } else { - zval_add_ref(entry_values); - switch (zend_hash_get_current_key_ex(Z_ARRVAL(new_return_value), &string_key, &string_key_len, &num_key, 0, &pos_values)) { - case HASH_KEY_IS_LONG: - add_index_zval(return_value, num_key, *entry_values); - break; - case HASH_KEY_IS_STRING: - add_assoc_zval_ex(return_value, string_key, string_key_len, *entry_values); - break; - } + zend_hash_move_forward_ex(Z_ARRVAL(new_return_value), &pos_values); } - zend_hash_move_forward_ex(Z_ARRVAL(new_return_value), &pos_values); + } else { + RETVAL_NULL(); } zval_dtor(&new_return_value); } else { Modified: php/php-src/branches/PHP_5_3/ext/mysqli/tests/mysqli_magic_quotes.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/mysqli/tests/mysqli_magic_quotes.phpt 2010-09-14 15:33:43 UTC (rev 303365) +++ php/php-src/branches/PHP_5_3/ext/mysqli/tests/mysqli_magic_quotes.phpt 2010-09-14 16:09:42 UTC (rev 303366) @@ -41,55 +41,35 @@ "\\0" => "\\\\0", "\\" => "\\\\", ); + $expectedBoth = array( + 0 => "\\'", + "'" => "\\'", + 1 => "\\\"", + '"' => "\\\"", + 2 => "\\\\0", + "\\0" => "\\\\0", + 3 => "\\\\", + "\\" => "\\\\", + ); if (!$res = mysqli_query($link, $query)) { printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $row = mysqli_fetch_row($res); - $idx = 0; - foreach ($expected as $key => $value) { - if (!isset($row[$idx])) - printf("[004] Index %d missing\n", $idx); - - if ($row[$idx] !== $value) - printf("[005] Expecting %d => %s got %d => %s\n", $idx, $value, $idx, $row[$idx]); - - unset($row[$idx]); - $idx++; + echo "Equal:";var_dump($row === array_values($expected)); + if ($row !== array_values($expected)) { + var_dump($row, array_values($expected)); } - if (count($row) != 0) { - printf("[006] Unexpected results, dumping\n"); - var_dump($row); - } $res->free(); if (!$res = mysqli_query($link, $query)) { printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } $row = mysqli_fetch_array($res, MYSQLI_BOTH); - $idx = 0; - foreach ($expected as $key => $value) { - if (!isset($row[$idx])) - printf("[008] Index %d missing\n", $idx); - - if ($row[$idx] !== $value) - printf("[009] Expecting %d => %s got %d => %s\n", $idx, $value, $idx, $row[$idx]); - - unset($row[$idx]); - $idx++; - - if (!isset($row[$key])) - printf("[010] Index %s missing\n", $key); - - if ($row[$key] !== $value) - printf("[011] Expecting %s => %s got %s => %s\n", $key, $value, $key, $row[$key]); - - unset($row[$key]); + echo "Equal:";var_dump($row === $expectedBoth); + if ($row !== $expectedBoth) { + var_dump($row, $expectedBoth); } - if (count($row) != 0) { - printf("[012] Unexpected results, dumping\n"); - var_dump($row); - } $res->free(); class fetch_object { @@ -120,15 +100,9 @@ print "done!"; ?> --EXPECTF-- -Deprecated: Directive 'magic_quotes_runtime' is deprecated in PHP 5.3 and greater in %s on line %d +Deprecated: Directive 'magic_quotes_runtime' is deprecated in PHP 5.3 and greater in Unknown on line %d Warning: mysqli_result::fetch_assoc(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_result::fetch_assoc(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_result::fetch_assoc(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_result::fetch_assoc(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d array(4) { ["'"]=> string(2) "\'" @@ -141,28 +115,12 @@ } Warning: mysqli_fetch_row(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d +Equal:bool(true) -Warning: mysqli_fetch_row(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_row(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_row(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - Warning: mysqli_fetch_array(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d +Equal:bool(true) -Warning: mysqli_fetch_array(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_array(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_array(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_object(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_object(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_object(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d - -Warning: mysqli_fetch_object(): magic_quotes_runtime are deprecated since PHP 5.3 in %s on line %d +Warning: mysqli_fetch_object(): magic_quotes_runtime are deprecated since PHP 5.3 in /work/vanilla/php/php-src/branches/PHP_5_3/ext/mysqli/tests/mysqli_magic_quotes.php on line 69 >'< => >\'< >"< => >\"< >\0< => >\\0<
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php