andrey                                   Fri, 12 Aug 2011 14:55:00 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=314838

Log:
prevent a crash if cs is NULL, which can happen with MS and lazy connections

Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
    U   php/php-src/branches/PHP_5_4/ext/mysqli/mysqli_nonapi.c
    U   php/php-src/trunk/ext/mysqli/mysqli_nonapi.c

Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c     2011-08-12 
14:32:14 UTC (rev 314837)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c     2011-08-12 
14:55:00 UTC (rev 314838)
@@ -916,7 +916,6 @@
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

-       object_init(return_value);

 #if !defined(MYSQLI_USE_MYSQLND)
        mysql_get_character_set_info(mysql->mysql, &cs);
@@ -930,6 +929,10 @@
        comment = cs.comment;
 #else
        cs = mysql->mysql->charset;
+       if (!cs) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The connection has 
no charset associated");
+               RETURN_NULL();
+       }
        name = cs->name;
        collation = cs->collation;
        minlength = cs->char_minlen;
@@ -938,6 +941,7 @@
        comment = cs->comment;
        state = 1;      /* all charsets are compiled in */
 #endif
+       object_init(return_value);

        add_property_string(return_value, "charset", (name) ? (char *)name : 
"", 1);
        add_property_string(return_value, "collation",(collation) ? (char 
*)collation : "", 1);

Modified: php/php-src/branches/PHP_5_4/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/mysqli/mysqli_nonapi.c     2011-08-12 
14:32:14 UTC (rev 314837)
+++ php/php-src/branches/PHP_5_4/ext/mysqli/mysqli_nonapi.c     2011-08-12 
14:55:00 UTC (rev 314838)
@@ -992,7 +992,6 @@
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

-       object_init(return_value);

 #if !defined(MYSQLI_USE_MYSQLND)
        mysql_get_character_set_info(mysql->mysql, &cs);
@@ -1006,6 +1005,10 @@
        comment = cs.comment;
 #else
        cs = mysql->mysql->charset;
+       if (!cs) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The connection has 
no charset associated");
+               RETURN_NULL();
+       }
        name = cs->name;
        collation = cs->collation;
        minlength = cs->char_minlen;
@@ -1014,6 +1017,7 @@
        comment = cs->comment;
        state = 1;      /* all charsets are compiled in */
 #endif
+       object_init(return_value);

        add_property_string(return_value, "charset", (name) ? (char *)name : 
"", 1);
        add_property_string(return_value, "collation",(collation) ? (char 
*)collation : "", 1);

Modified: php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_nonapi.c        2011-08-12 14:32:14 UTC 
(rev 314837)
+++ php/php-src/trunk/ext/mysqli/mysqli_nonapi.c        2011-08-12 14:55:00 UTC 
(rev 314838)
@@ -992,7 +992,6 @@
        }
        MYSQLI_FETCH_RESOURCE_CONN(mysql, &mysql_link, MYSQLI_STATUS_VALID);

-       object_init(return_value);

 #if !defined(MYSQLI_USE_MYSQLND)
        mysql_get_character_set_info(mysql->mysql, &cs);
@@ -1006,6 +1005,10 @@
        comment = cs.comment;
 #else
        cs = mysql->mysql->charset;
+       if (!cs) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The connection has 
no charset associated");
+               RETURN_NULL();
+       }
        name = cs->name;
        collation = cs->collation;
        minlength = cs->char_minlen;
@@ -1014,6 +1017,7 @@
        comment = cs->comment;
        state = 1;      /* all charsets are compiled in */
 #endif
+       object_init(return_value);

        add_property_string(return_value, "charset", (name) ? (char *)name : 
"", 1);
        add_property_string(return_value, "collation",(collation) ? (char 
*)collation : "", 1);

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

Reply via email to