summaryrefslogtreecommitdiff
path: root/ext/mysqli/mysqli_nonapi.c
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
commit566a367ef6bfcb604620cdc5cc455af553cedccb (patch)
treeb05f8139117c1a4dfb97d66ecd00f5e755e32511 /ext/mysqli/mysqli_nonapi.c
parent94b7b548c5139f7f2325c300dfb1038feede7bc1 (diff)
downloadphp-git-566a367ef6bfcb604620cdc5cc455af553cedccb.tar.gz
prevent a crash if cs is NULL, which can happen with MS and lazy connections
Diffstat (limited to 'ext/mysqli/mysqli_nonapi.c')
-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);