Skip to content
Permalink
Browse files

Fixed bug #67348: Reading $dbc->stat modifies $dbc->affected_rows

  • Loading branch information...
derickr committed Jun 21, 2019
1 parent 152ccfb commit 579562176b71820ad49d43b2c841642fef12fe57
4 NEWS
@@ -15,6 +15,10 @@ PHP NEWS
- GD:
. Added TGA read support. (cmb)

- MySQLi:
. Fixed bug #67348 (Reading $dbc->stat modifies $dbc->affected_rows).
(Derick)

- Opcache:
. Fixed bug #78106 (Path resolution fails if opcache disabled during request).
(Nikita)
@@ -634,7 +634,6 @@ PHP_MINIT_FUNCTION(mysqli)
zend_declare_property_null(ce, "insert_id", sizeof("insert_id") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "server_info", sizeof("server_info") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "server_version", sizeof("server_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "stat", sizeof("stat") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "sqlstate", sizeof("sqlstate") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "protocol_version", sizeof("protocol_version") - 1, ZEND_ACC_PUBLIC);
zend_declare_property_null(ce, "thread_id", sizeof("thread_id") - 1, ZEND_ACC_PUBLIC);
@@ -234,38 +234,6 @@ MYSQLI_MAP_PROPERTY_FUNC_STRING(link_sqlstate_read, mysql_sqlstate, MYSQLI_GET_M
MYSQLI_MAP_PROPERTY_FUNC_LONG(link_thread_id_read, mysql_thread_id, MYSQLI_GET_MYSQL(MYSQLI_STATUS_VALID), zend_ulong, ZEND_ULONG_FMT)
MYSQLI_MAP_PROPERTY_FUNC_LONG(link_warning_count_read, mysql_warning_count, MYSQLI_GET_MYSQL(MYSQLI_STATUS_VALID), zend_ulong, ZEND_ULONG_FMT)

/* {{{ property link_stat_read */
static zval *link_stat_read(mysqli_object *obj, zval *retval)
{
MY_MYSQL *mysql;

ZVAL_NULL(retval);

#if defined(MYSQLI_USE_MYSQLND)
CHECK_STATUS(MYSQLI_STATUS_INITIALIZED);
#else
CHECK_STATUS(MYSQLI_STATUS_VALID);
#endif

mysql = (MY_MYSQL *)((MYSQLI_RESOURCE *)(obj->ptr))->ptr;

if (mysql) {
#if defined(MYSQLI_USE_MYSQLND)
zend_string * stat_msg;
if (mysqlnd_stat(mysql->mysql, &stat_msg) == PASS) {
ZVAL_STR(retval, stat_msg);
}
#else
char * stat_msg;
if ((stat_msg = (char *)mysql_stat(mysql->mysql))) {
ZVAL_STRING(retval, stat_msg);
}
#endif
}
return retval;
}
/* }}} */

/* result properties */

/* {{{ property result_type_read */
@@ -435,7 +403,6 @@ const mysqli_property_entry mysqli_link_property_entries[] = {
{"insert_id", sizeof("insert_id") - 1, link_insert_id_read, NULL},
{"server_info", sizeof("server_info") - 1, link_server_info_read, NULL},
{"server_version", sizeof("server_version") - 1, link_server_version_read, NULL},
{"stat", sizeof("stat") - 1, link_stat_read, NULL},
{"sqlstate", sizeof("sqlstate") - 1, link_sqlstate_read, NULL},
{"protocol_version",sizeof("protocol_version") - 1, link_protocol_version_read, NULL},
{"thread_id", sizeof("thread_id") - 1, link_thread_id_read, NULL},
@@ -92,8 +92,6 @@ object(mysqli)#%d (%d) {
string(%d) "%s"
["server_version"]=>
int(%d)
["stat"]=>
string(%d) "Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d"
["sqlstate"]=>
string(5) "00000"
["protocol_version"]=>
@@ -132,8 +130,6 @@ object(mysqli)#%d (%d) {
bool(false)
["server_version"]=>
bool(false)
["stat"]=>
NULL
["sqlstate"]=>
bool(false)
["protocol_version"]=>

This file was deleted.

@@ -1,7 +1,7 @@
<?php
/*
Default values are "localhost", "root",
database "stest" and empty password.
database "test" and empty password.
Change the MYSQL_TEST environment values
if you want to use another configuration
*/
@@ -53,7 +53,7 @@ require_once('skipifconnectfailure.inc');
'set_charset' => true,
'set_opt' => true,
'ssl_set' => true,
'stat' => true,
'stat' => true,
'stmt_init' => true,
'store_result' => true,
'thread_safe' => true,
@@ -109,7 +109,6 @@ require_once('skipifconnectfailure.inc');
"server_info" => true,
"server_version" => true,
"sqlstate" => true,
"stat" => true,
"thread_id" => true,
"warning_count" => true,
);
@@ -200,11 +199,6 @@ require_once('skipifconnectfailure.inc');
$mysqli->sqlstate, gettype($mysqli->sqlstate),
mysqli_sqlstate($link), gettype(mysqli_sqlstate($link)));
assert(soundex(mysqli_stat($link)) == soundex($mysqli->stat));
printf("mysqli->stat = '%s'/%s ('%s'/%s)\n",
$mysqli->stat, gettype($mysqli->stat),
mysqli_stat($link), gettype(mysqli_stat($link)));
assert(mysqli_get_host_info($link) === $mysqli->host_info);
printf("mysqli->host_info = '%s'/%s ('%s'/%s)\n",
$mysqli->host_info, gettype($mysqli->host_info),
@@ -288,7 +282,6 @@ mysqli->error = ''/string (''/string)
mysqli->field_count = '0'/integer ('0'/integer)
mysqli->insert_id = '0'/integer ('0'/integer)
mysqli->sqlstate = '00000'/string ('00000'/string)
mysqli->stat = 'Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string ('Uptime: %d Threads: %d Questions: %d Slow queries: %d Opens: %d Flush tables: %d Open tables: %d Queries per second avg: %d.%d'/string)
mysqli->host_info = '%s'/string ('%s'/string)
mysqli->info = ''/NULL (''/NULL)
mysqli->thread_id = '%d'/integer ('%d'/integer)
@@ -160,7 +160,6 @@ protocol_version = 'false'
server_info = 'false'
server_version = 'false'
sqlstate = 'false'
stat = 'false'
thread_id = 'false'
warning_count = 'false'

@@ -179,7 +178,6 @@ info = 'false'
insert_id = 'false'
server_info = 'false'
server_version = 'false'
stat = 'false'
sqlstate = 'false'
protocol_version = 'false'
thread_id = 'false'
@@ -233,7 +231,6 @@ protocol_version = 'false'
server_info = 'false'
server_version = 'false'
sqlstate = 'false'
stat = 'false'
thread_id = 'false'
warning_count = 'false'

@@ -252,7 +249,6 @@ info = 'false'
insert_id = 'false'
server_info = 'false'
server_version = 'false'
stat = 'false'
sqlstate = 'false'
protocol_version = 'false'
thread_id = 'false'
@@ -1317,14 +1317,6 @@ isStatic: no
isDefault: yes
Modifiers: 1

Inspecting property 'stat'
isPublic: yes
isPrivate: no
isProtected: no
isStatic: no
isDefault: yes
Modifiers: 1

Inspecting property 'thread_id'
isPublic: yes
isPrivate: no
@@ -1356,7 +1348,6 @@ Default property 'protocol_version'
Default property 'server_info'
Default property 'server_version'
Default property 'sqlstate'
Default property 'stat'
Default property 'thread_id'
Default property 'warning_count'
done!
@@ -44,9 +44,6 @@ require_once('skipifconnectfailure.inc');
if ($link->info != 'Records: 6 Duplicates: 0 Warnings: 0') {
printf("[008] mysqlnd used to be more verbose and used to support SELECT\n");
}
if ($link->stat != NULL) {
printf("[009] NULL expected because of error.\n");
}
} else {
if ($link->info != NULL) {
printf("[008] Time for wonders - libmysql has started to support SELECT, change test\n");
@@ -123,8 +120,6 @@ object(mysqli)#%d (%d) {
string(%d) "%s"
["server_version"]=>
int(%d)
["stat"]=>

This comment has been minimized.

Copy link
@staabm

staabm Jun 21, 2019

Contributor

Should this be noted somewhere when this property will no longer exist? Sounds like a BC break?

This comment has been minimized.

Copy link
@derickr

derickr Jun 22, 2019

Author Contributor

Probably, but I don't know where, as this property was never documented in the first place. /cc @nikic ?

This comment has been minimized.

Copy link
@nikic

nikic Jun 22, 2019

Member

It should be mentioned in UPGRADING.

This comment has been minimized.

Copy link
@petk

petk Jun 25, 2019

Contributor

UPGRADING file update: #4310

This comment has been minimized.

Copy link
@derickr

derickr via email Jun 25, 2019

Author Contributor
%s
["sqlstate"]=>
string(5) "HY000"
["protocol_version"]=>
@@ -207,8 +207,6 @@ object(mysqli)#%d (%d) {
bool(false)
["server_version"]=>
bool(false)
["stat"]=>
bool(false)
["sqlstate"]=>
bool(false)
["protocol_version"]=>

0 comments on commit 5795621

Please sign in to comment.
You can’t perform that action at this time.