Commit:    40fabf68edd5524b9ce0cda925d6c7888d8441c3
Author:    Xinchen Hui <larue...@php.net>         Fri, 30 Nov 2012 14:28:32 
+0800
Parents:   dc2192c08766939700260128684255772ba4296f
Branches:  PHP-5.3

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=40fabf68edd5524b9ce0cda925d6c7888d8441c3

Log:
Fixed bug #63398 (Segfault when polling closed link)

Bugs:
https://bugs.php.net/63398

Changed paths:
  M  NEWS
  M  ext/mysqli/mysqli_nonapi.c
  A  ext/mysqli/tests/bug63398.phpt


Diff:
diff --git a/NEWS b/NEWS
index 53f0112..68a88ed 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,9 @@ PHP                                                           
             NEWS
 - Imap:
   . Fixed Bug #63126 DISABLE_AUTHENTICATOR ignores array (Remi)
 
+- MySQLnd:
+  . Fixed bug #63398 (Segfault when polling closed link). (Laruence)
+
 - Reflection:
   . Fixed Bug #63614 (Fatal error on Reflection). (Laruence)
 
diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c
index 0ef67a2..a6cbcf1 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -607,7 +607,7 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND 
**in_array, zval *out_a
        MYSQLND **p = in_array;
        HashTable *new_hash;
        zval **elem, **dest_elem;
-       int ret = 0;
+       int ret = 0, i = 0;
 
        ALLOC_HASHTABLE(new_hash);
        zend_hash_init(new_hash, zend_hash_num_elements(Z_ARRVAL_P(out_array)), 
NULL, ZVAL_PTR_DTOR, 0);
@@ -616,13 +616,19 @@ static int mysqlnd_zval_array_from_mysqlnd_array(MYSQLND 
**in_array, zval *out_a
                 zend_hash_get_current_data(Z_ARRVAL_P(out_array), (void **) 
&elem) == SUCCESS;
                 zend_hash_move_forward(Z_ARRVAL_P(out_array)))
        {
+               i++;
                if (Z_TYPE_PP(elem) != IS_OBJECT || 
!instanceof_function(Z_OBJCE_PP(elem), mysqli_link_class_entry TSRMLS_CC)) {
                        continue;
                }
                {
                        MY_MYSQL *mysql;
+                       MYSQLI_RESOURCE *my_res;
                        mysqli_object *intern = (mysqli_object 
*)zend_object_store_get_object(*elem TSRMLS_CC);
-                       mysql = (MY_MYSQL *) ((MYSQLI_RESOURCE 
*)intern->ptr)->ptr;
+                       if (!(my_res = (MYSQLI_RESOURCE *)intern->ptr)) {
+                               php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"[%d] Couldn't fetch %s", i, intern->zo.ce->name);
+                               continue;
+                       }
+                       mysql = (MY_MYSQL *) my_res->ptr;
                        if (mysql->mysql == *p) {
                                zend_hash_next_index_insert(new_hash, (void 
*)elem, sizeof(zval *), (void **)&dest_elem);
                                if (dest_elem) {
diff --git a/ext/mysqli/tests/bug63398.phpt b/ext/mysqli/tests/bug63398.phpt
new file mode 100644
index 0000000..6dffa8c
--- /dev/null
+++ b/ext/mysqli/tests/bug63398.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Bug #63398 (Segfault when polling closed link)
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+require_once("connect.inc");
+if (!$IS_MYSQLND) {
+    die("skip mysqlnd only test");
+}
+?>
+--FILE--
+<?php
+$link = new mysqli('localhost', 'test', NULL, 'test');
+
+mysqli_close($link);
+
+$read = $error = $reject = array();
+$read[] = $error[] = $reject[] = $link;
+
+mysqli_poll($read, $error, $reject, 1);
+
+echo "okey";
+?>
+--EXPECTF--
+Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
+
+Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
+
+Warning: mysqli_poll(): No stream arrays were passed in %sbug63398.php on line 
%d
+
+Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
+
+Warning: mysqli_poll(): [1] Couldn't fetch mysqli in %sbug63398.php on line %d
+okey


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to