From: Andrey Hristov Date: Fri, 12 Aug 2011 14:55:00 +0000 (+0000) Subject: prevent a crash if cs is NULL, which can happen with MS and lazy connections X-Git-Tag: php-5.4.0beta1~435 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d803c2f8275f1c4d6b392108028698e686fa8607;p=php prevent a crash if cs is NULL, which can happen with MS and lazy connections --- diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 2844c4df1b..d720f478b0 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -992,7 +992,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); @@ -1006,6 +1005,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; @@ -1014,6 +1017,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);