Skip to content

Commit

Permalink
Fixed bug #65825
Browse files Browse the repository at this point in the history
Set error_info when we fail to read a packet, instead of throwing
a warning. Additionally we also need to populate the right
error_info in rowp_read -- we'll later take the error from the
packet, not the connection.

No test case, as this is hard to reliably test. I'm using the
test case from:
#2131 (comment)
  • Loading branch information
nikic committed Oct 28, 2020
1 parent f547412 commit a66d73d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ PHP NEWS
- PDO MySQL:
. Fixed bug #66528 (No PDOException or errorCode if database becomes
unavailable before PDO::commit). (Nikita)
. Fixed bug #65825 (PDOStatement::fetch() does not throw exception on broken
server connection). (Nikita)

29 Oct 2020, PHP 7.4.12

Expand Down
17 changes: 13 additions & 4 deletions ext/mysqlnd/mysqlnd_wireprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,15 @@ php_mysqlnd_rset_field_read(MYSQLND_CONN_DATA * conn, void * _packet)
}
/* }}} */

/* Like SET_CLIENT_ERROR, but for packet error_info. The type is the same,
* but only some parts of it are used. */
static void set_packet_error(
MYSQLND_ERROR_INFO *info, unsigned err_no, const char *sqlstate, const char *error)
{
info->error_no = err_no;
strlcpy(info->sqlstate, sqlstate, sizeof(info->sqlstate));
strlcpy(info->error, error, sizeof(info->error));
}

/* {{{ php_mysqlnd_read_row_ex */
static enum_func_status
Expand Down Expand Up @@ -1396,7 +1405,7 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,

if (UNEXPECTED(PASS != (ret = pfc->data->m.receive(pfc, vio, p, header.size, stats, error_info)))) {
DBG_ERR("Empty row packet body");
php_error(E_WARNING, "Empty row packet body");
set_packet_error(error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
} else {
while (header.size >= MYSQLND_MAX_PACKET_SIZE) {
if (FAIL == mysqlnd_read_header(pfc, vio, &header, stats, error_info)) {
Expand Down Expand Up @@ -1425,7 +1434,7 @@ php_mysqlnd_read_row_ex(MYSQLND_PFC * pfc,

if (PASS != (ret = pfc->data->m.receive(pfc, vio, p, header.size, stats, error_info))) {
DBG_ERR("Empty row packet body");
php_error(E_WARNING, "Empty row packet body");
set_packet_error(error_info, CR_SERVER_GONE_ERROR, UNKNOWN_SQLSTATE, mysqlnd_server_gone);
break;
}
}
Expand Down Expand Up @@ -1720,8 +1729,8 @@ php_mysqlnd_rowp_read_text_protocol_c(MYSQLND_ROW_BUFFER * row_buffer, zval * fi
static enum_func_status
php_mysqlnd_rowp_read(MYSQLND_CONN_DATA * conn, void * _packet)
{
MYSQLND_PACKET_ROW *packet= (MYSQLND_PACKET_ROW *) _packet;
MYSQLND_ERROR_INFO * error_info = conn->error_info;
MYSQLND_PACKET_ROW *packet = (MYSQLND_PACKET_ROW *) _packet;
MYSQLND_ERROR_INFO * error_info = &packet->error_info;
MYSQLND_PFC * pfc = conn->protocol_frame_codec;
MYSQLND_VIO * vio = conn->vio;
MYSQLND_STATS * stats = conn->stats;
Expand Down

0 comments on commit a66d73d

Please sign in to comment.