]> granicus.if.org Git - php/commitdiff
prevent a crash if cs is NULL, which can happen with MS and lazy connections
authorAndrey Hristov <andrey@php.net>
Fri, 12 Aug 2011 14:55:00 +0000 (14:55 +0000)
committerAndrey Hristov <andrey@php.net>
Fri, 12 Aug 2011 14:55:00 +0000 (14:55 +0000)
ext/mysqli/mysqli_nonapi.c

index 4c281c27617fd09c89314b51d46beae39585980d..efc1801dbfefc8eb4e17c38221da19d68cbd5ab4 100644 (file)
@@ -916,7 +916,6 @@ PHP_FUNCTION(mysqli_get_charset)
        }
        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 @@ PHP_FUNCTION(mysqli_get_charset)
        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 @@ PHP_FUNCTION(mysqli_get_charset)
        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);