andrey          Thu Dec 22 18:11:39 2005 EDT

  Added files:                 (Branch: PHP_5_1)
    /php-src/ext/mysqli/tests   bug35759.phpt 

  Modified files:              
    /php-src/ext/mysqli mysqli.c mysqli_api.c 
  Log:
  fix for bug# 35759 
  (mysqli_stmt_bind_result() makes huge allocation when column empty)
  #this shows some leaks now, which has to be investigated but closes the
  #bug report.
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/mysqli.c?r1=1.72.2.5&r2=1.72.2.6&diff_format=u
Index: php-src/ext/mysqli/mysqli.c
diff -u php-src/ext/mysqli/mysqli.c:1.72.2.5 
php-src/ext/mysqli/mysqli.c:1.72.2.6
--- php-src/ext/mysqli/mysqli.c:1.72.2.5        Tue Nov 15 14:28:40 2005
+++ php-src/ext/mysqli/mysqli.c Thu Dec 22 18:11:39 2005
@@ -15,7 +15,7 @@
   | Author: Georg Richter <[EMAIL PROTECTED]>                                |
   +----------------------------------------------------------------------+
 
-  $Id: mysqli.c,v 1.72.2.5 2005/11/15 14:28:40 dmitry Exp $ 
+  $Id: mysqli.c,v 1.72.2.6 2005/12/22 18:11:39 andrey Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -155,11 +155,11 @@
                        MY_STMT *stmt = (MY_STMT *)my_res->ptr;
                        php_clear_stmt_bind(stmt);
                }
-       } else if (instanceof_function(intern->zo.ce, mysqli_result_class_entry 
TSRMLS_CC)) { /* stmt object */
+       } else if (instanceof_function(intern->zo.ce, mysqli_result_class_entry 
TSRMLS_CC)) { /* result object */
                if (my_res && my_res->ptr) {
                        mysql_free_result(my_res->ptr);
                }
-       } else if (instanceof_function(intern->zo.ce, 
mysqli_warning_class_entry TSRMLS_CC)) { /* stmt object */
+       } else if (instanceof_function(intern->zo.ce, 
mysqli_warning_class_entry TSRMLS_CC)) { /* warning object */
                if (my_res && my_res->ptr) {
                        php_clear_warnings((MYSQLI_WARNING *)my_res->info);
                }
@@ -459,7 +459,7 @@
        zend_hash_init(&mysqli_driver_properties, 0, NULL, NULL, 1);
        MYSQLI_ADD_PROPERTIES(&mysqli_driver_properties, 
mysqli_driver_property_entries);
        zend_hash_add(&classes, ce->name, ce->name_length+1, 
&mysqli_driver_properties, sizeof(mysqli_driver_properties), NULL);
-    ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
+       ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
 
        REGISTER_MYSQLI_CLASS_ENTRY("mysqli", mysqli_link_class_entry, 
mysqli_link_methods);
        ce = mysqli_link_class_entry;
@@ -469,7 +469,7 @@
 
        REGISTER_MYSQLI_CLASS_ENTRY("mysqli_warning", 
mysqli_warning_class_entry, mysqli_warning_methods);
        ce = mysqli_warning_class_entry;
-    ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
+       ce->ce_flags |= ZEND_ACC_FINAL_CLASS | ZEND_ACC_PROTECTED;
        zend_hash_init(&mysqli_warning_properties, 0, NULL, NULL, 1);
        MYSQLI_ADD_PROPERTIES(&mysqli_warning_properties, 
mysqli_warning_property_entries);
        zend_hash_add(&classes, ce->name, ce->name_length+1, 
&mysqli_warning_properties, sizeof(mysqli_warning_properties), NULL);
http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/mysqli_api.c?r1=1.118.2.10&r2=1.118.2.11&diff_format=u
Index: php-src/ext/mysqli/mysqli_api.c
diff -u php-src/ext/mysqli/mysqli_api.c:1.118.2.10 
php-src/ext/mysqli/mysqli_api.c:1.118.2.11
--- php-src/ext/mysqli/mysqli_api.c:1.118.2.10  Thu Dec  1 14:12:55 2005
+++ php-src/ext/mysqli/mysqli_api.c     Thu Dec 22 18:11:39 2005
@@ -15,7 +15,7 @@
   | Author: Georg Richter <[EMAIL PROTECTED]>                                |
   +----------------------------------------------------------------------+
 
-  $Id: mysqli_api.c,v 1.118.2.10 2005/12/01 14:12:55 andrey Exp $ 
+  $Id: mysqli_api.c,v 1.118.2.11 2005/12/22 18:11:39 andrey Exp $ 
 */
 
 #ifdef HAVE_CONFIG_H
@@ -323,20 +323,26 @@
 #ifdef FIELD_TYPE_NEWDECIMAL
                        case MYSQL_TYPE_NEWDECIMAL:
 #endif
+                       {
+                               ulong tmp;
                                stmt->result.buf[ofs].type = IS_STRING;
                                /*
                                        If the user has called 
$stmt->store_result() then we have asked
                                        max_length to be updated. this is done 
only for BLOBS because we don't want to allocate
                                        big chunkgs of memory 2^16 or 2^24 
                                */
-                               if (stmt->stmt->fields[ofs].max_length == 0) {
+                               if (stmt->stmt->fields[ofs].max_length == 0 &&
+                                       !mysql_stmt_attr_get(stmt->stmt, 
STMT_ATTR_UPDATE_MAX_LENGTH, &tmp) && !tmp)
+                               {
                                        stmt->result.buf[ofs].buflen =
                                                (stmt->stmt->fields) ? 
(stmt->stmt->fields[ofs].length) ? stmt->stmt->fields[ofs].length + 1: 256: 256;
                                } else {
                                        /*
                                                the user has called 
store_result(). if he does not there is no way to determine the
+                                               libmysql does not allow us to 
allocate 0 bytes for a buffer so we try 1
                                        */
-                                       stmt->result.buf[ofs].buflen = 
stmt->stmt->fields[ofs].max_length;
+                                       if (!(stmt->result.buf[ofs].buflen = 
stmt->stmt->fields[ofs].max_length))
+                                               ++stmt->result.buf[ofs].buflen;
                                }
                                stmt->result.buf[ofs].val = (char 
*)emalloc(stmt->result.buf[ofs].buflen);
                                bind[ofs].buffer_type = MYSQL_TYPE_STRING;
@@ -345,6 +351,7 @@
                                bind[ofs].buffer_length = 
stmt->result.buf[ofs].buflen;
                                bind[ofs].length = 
&stmt->result.buf[ofs].buflen;
                                break;
+                       }
                        default:
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Server returned unknown type %ld. Probably your client library is incompatible 
with the server version you use!", col_type);
                                break;

http://cvs.php.net/viewcvs.cgi/php-src/ext/mysqli/tests/bug35759.phpt?view=markup&rev=1.1
Index: php-src/ext/mysqli/tests/bug35759.phpt
+++ php-src/ext/mysqli/tests/bug35759.phpt

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

Reply via email to