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
commitaa480a4f4f8e4f977f58f97865d073766cd735e2 (patch)
treef2fbe03888bb2769a91d7663793f9d1534144539 /ext/mysqli/mysqli_nonapi.c
parentd3d7da14e6ab41cd759cf805374c9589f7d0abd0 (diff)
downloadphp-git-aa480a4f4f8e4f977f58f97865d073766cd735e2.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 4c281c2761..efc1801dbf 100644
--- a/ext/mysqli/mysqli_nonapi.c
+++ b/ext/mysqli/mysqli_nonapi.c
@@ -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);