summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2011-08-12 14:55:00 +0000
committerAndrey Hristov <andrey@php.net>2011-08-12 14:55:00 +0000
commitd803c2f8275f1c4d6b392108028698e686fa8607 (patch)
tree550d414fb105f99452515148530fa5545377cece
parent6e54341273cef37cd9010177435eb86b81a91491 (diff)
downloadphp-git-d803c2f8275f1c4d6b392108028698e686fa8607.tar.gz
prevent a crash if cs is NULL, which can happen with MS and lazy connections
-rw-r--r--ext/mysqli/mysqli_nonapi.c6
1 files changed, 5 insertions, 1 deletions
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);