]> granicus.if.org Git - php/commitdiff
unify magic quotes handling. Also fix a problem which
authorAndrey Hristov <andrey@php.net>
Tue, 14 Sep 2010 16:09:42 +0000 (16:09 +0000)
committerAndrey Hristov <andrey@php.net>
Tue, 14 Sep 2010 16:09:42 +0000 (16:09 +0000)
resulted in a longjmp in debug PHP,because of usage of
zval that is NULL in a hash context.

ext/mysqli/mysqli.c
ext/mysqli/tests/mysqli_magic_quotes.phpt

index 6cdee91a7a6e578c8e05b9bb1de65ecb4f79c4a2..f1c16a722fe827a4fa327c8d47d9ccf7755d31ca 100644 (file)
@@ -1092,6 +1092,7 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
        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 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
 
                                /* 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 @@ void php_mysqli_fetch_into_hash(INTERNAL_FUNCTION_PARAMETERS, int override_flags
                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;
-                               }
-                       } 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;
+               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;
+                                       }
                                }
+                               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 {
index 76bbda9d1f4f3e461068b7cb21f13b734e15a810..72a6e2b7f8cd01cbd8673c862a87d96063f9165e 100644 (file)
@@ -41,25 +41,24 @@ magic_quotes_runtime=1
                "\\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++;
-       }
-       if (count($row) != 0) {
-               printf("[006] Unexpected results, dumping\n");
-               var_dump($row);
+       echo "Equal:";var_dump($row === array_values($expected));
+       if ($row !== array_values($expected)) {
+               var_dump($row, array_values($expected));
        }
        $res->free();
 
@@ -67,28 +66,9 @@ magic_quotes_runtime=1
                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]);
-       }
-       if (count($row) != 0) {
-               printf("[012] Unexpected results, dumping\n");
-               var_dump($row);
+       echo "Equal:";var_dump($row === $expectedBoth);
+       if ($row !== $expectedBoth) {
+               var_dump($row, $expectedBoth);
        }
        $res->free();
 
@@ -120,13 +100,7 @@ magic_quotes_runtime=1
        print "done!";
 ?>
 --EXPECTF--
-Deprecated: Directive 'magic_quotes_runtime' is deprecated in PHP 5.3 and greater 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
+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
 array(4) {
@@ -141,28 +115,12 @@ array(4) {
 }
 
 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_row(): 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
+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<