mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix crashes with pconn in ext/mysql
This commit is contained in:
parent
99139b574d
commit
de29322de4
6 changed files with 28 additions and 15 deletions
|
@ -800,6 +800,10 @@ static void php_mysql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
|
||||||
#endif
|
#endif
|
||||||
mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));
|
mysql_options(mysql->conn, MYSQL_OPT_LOCAL_INFILE, (char *)&MySG(allow_local_infile));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
#ifdef HAVE_MYSQLND
|
||||||
|
mysqlnd_restart_psession(mysql->conn);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);
|
ZEND_REGISTER_RESOURCE(return_value, mysql, le_plink);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "mysqlnd_result.h"
|
#include "mysqlnd_result.h"
|
||||||
#include "mysqlnd_statistics.h"
|
#include "mysqlnd_statistics.h"
|
||||||
#include "mysqlnd_charset.h"
|
#include "mysqlnd_charset.h"
|
||||||
|
#include "php_ini.h"
|
||||||
#include "ext/standard/basic_functions.h"
|
#include "ext/standard/basic_functions.h"
|
||||||
#include "ext/standard/php_lcg.h"
|
#include "ext/standard/php_lcg.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
|
@ -263,7 +264,8 @@ mysqlnd_simple_command_handle_response(MYSQLND *conn, enum php_mysql_packet_type
|
||||||
SET_ERROR_AFF_ROWS(conn);
|
SET_ERROR_AFF_ROWS(conn);
|
||||||
} else {
|
} else {
|
||||||
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
||||||
ok_response.message, ok_response.message_len);
|
ok_response.message, ok_response.message_len,
|
||||||
|
conn->persistent);
|
||||||
|
|
||||||
conn->upsert_status.warning_count = ok_response.warning_count;
|
conn->upsert_status.warning_count = ok_response.warning_count;
|
||||||
conn->upsert_status.server_status = ok_response.server_status;
|
conn->upsert_status.server_status = ok_response.server_status;
|
||||||
|
@ -389,6 +391,11 @@ MYSQLND_METHOD(mysqlnd_conn, set_server_option)(MYSQLND * const conn,
|
||||||
PHPAPI void mysqlnd_restart_psession(MYSQLND *conn)
|
PHPAPI void mysqlnd_restart_psession(MYSQLND *conn)
|
||||||
{
|
{
|
||||||
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CONNECT_REUSED);
|
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_CONNECT_REUSED);
|
||||||
|
/* Free here what should not be seen by the next script */
|
||||||
|
if (conn->last_message) {
|
||||||
|
pefree(conn->last_message, conn->persistent);
|
||||||
|
conn->last_message = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
@ -613,7 +620,8 @@ PHPAPI MYSQLND *mysqlnd_connect(MYSQLND *conn,
|
||||||
conn->upsert_status.server_status = greet_packet.server_status;
|
conn->upsert_status.server_status = greet_packet.server_status;
|
||||||
conn->upsert_status.affected_rows = 0;
|
conn->upsert_status.affected_rows = 0;
|
||||||
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
||||||
ok_packet.message, ok_packet.message_len);
|
ok_packet.message, ok_packet.message_len,
|
||||||
|
conn->persistent);
|
||||||
|
|
||||||
SET_EMPTY_ERROR(conn->error_info);
|
SET_EMPTY_ERROR(conn->error_info);
|
||||||
|
|
||||||
|
@ -1661,7 +1669,7 @@ PHP_INI_END()
|
||||||
|
|
||||||
/* {{{ PHP_MINIT_FUNCTION
|
/* {{{ PHP_MINIT_FUNCTION
|
||||||
*/
|
*/
|
||||||
PHP_MINIT_FUNCTION(mysqlnd)
|
static PHP_MINIT_FUNCTION(mysqlnd)
|
||||||
{
|
{
|
||||||
REGISTER_INI_ENTRIES();
|
REGISTER_INI_ENTRIES();
|
||||||
|
|
||||||
|
@ -1673,7 +1681,7 @@ PHP_MINIT_FUNCTION(mysqlnd)
|
||||||
|
|
||||||
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
/* {{{ PHP_MSHUTDOWN_FUNCTION
|
||||||
*/
|
*/
|
||||||
PHP_MSHUTDOWN_FUNCTION(mysqlnd)
|
static PHP_MSHUTDOWN_FUNCTION(mysqlnd)
|
||||||
{
|
{
|
||||||
mysqlnd_library_end();
|
mysqlnd_library_end();
|
||||||
|
|
||||||
|
|
|
@ -109,10 +109,10 @@
|
||||||
#define SET_ERROR_AFF_ROWS(s) (s)->upsert_status.affected_rows = (mynd_ulonglong) ~0
|
#define SET_ERROR_AFF_ROWS(s) (s)->upsert_status.affected_rows = (mynd_ulonglong) ~0
|
||||||
|
|
||||||
/* Error handling */
|
/* Error handling */
|
||||||
#define SET_NEW_MESSAGE(buf, buf_len, message, len) \
|
#define SET_NEW_MESSAGE(buf, buf_len, message, len, persistent) \
|
||||||
{\
|
{\
|
||||||
if ((buf)) { \
|
if ((buf)) { \
|
||||||
efree((buf)); \
|
pefree((buf), (persistent)); \
|
||||||
} \
|
} \
|
||||||
(buf) = (message); \
|
(buf) = (message); \
|
||||||
(buf_len) = (len); \
|
(buf_len) = (len); \
|
||||||
|
@ -120,10 +120,10 @@
|
||||||
(message) = NULL; \
|
(message) = NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SET_EMPTY_MESSAGE(buf, buf_len) \
|
#define SET_EMPTY_MESSAGE(buf, buf_len, persistent) \
|
||||||
{\
|
{\
|
||||||
if ((buf)) { \
|
if ((buf)) { \
|
||||||
efree((buf)); \
|
pefree((buf), (persistent)); \
|
||||||
(buf) = NULL; \
|
(buf) = NULL; \
|
||||||
} \
|
} \
|
||||||
(buf_len) = 0; \
|
(buf_len) = 0; \
|
||||||
|
|
|
@ -269,7 +269,8 @@ mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT *stmt TSRMLS_DC
|
||||||
conn->upsert_status.affected_rows = rset_header.affected_rows;
|
conn->upsert_status.affected_rows = rset_header.affected_rows;
|
||||||
conn->upsert_status.last_insert_id = rset_header.last_insert_id;
|
conn->upsert_status.last_insert_id = rset_header.last_insert_id;
|
||||||
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
SET_NEW_MESSAGE(conn->last_message, conn->last_message_len,
|
||||||
rset_header.info_or_local_file, rset_header.info_or_local_file_len);
|
rset_header.info_or_local_file, rset_header.info_or_local_file_len,
|
||||||
|
conn->persistent);
|
||||||
/* Result set can follow UPSERT statement, check server_status */
|
/* Result set can follow UPSERT statement, check server_status */
|
||||||
if (conn->upsert_status.server_status & SERVER_MORE_RESULTS_EXISTS) {
|
if (conn->upsert_status.server_status & SERVER_MORE_RESULTS_EXISTS) {
|
||||||
conn->state = CONN_NEXT_RESULT_PENDING;
|
conn->state = CONN_NEXT_RESULT_PENDING;
|
||||||
|
@ -284,7 +285,7 @@ mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT *stmt TSRMLS_DC
|
||||||
MYSQLND_RES *result;
|
MYSQLND_RES *result;
|
||||||
uint stat = -1;
|
uint stat = -1;
|
||||||
|
|
||||||
SET_EMPTY_MESSAGE(conn->last_message, conn->last_message_len);
|
SET_EMPTY_MESSAGE(conn->last_message, conn->last_message_len, conn->persistent);
|
||||||
|
|
||||||
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_RSET_QUERY);
|
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_RSET_QUERY);
|
||||||
memset(&conn->upsert_status, 0, sizeof(conn->upsert_status));
|
memset(&conn->upsert_status, 0, sizeof(conn->upsert_status));
|
||||||
|
|
|
@ -100,7 +100,7 @@ extern MYSQLND_STATS *mysqlnd_global_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3) \
|
#define MYSQLND_INC_CONN_STATISTIC_W_VALUE3(conn_stats, statistic1, value1, statistic2, value2, statistic3, value3) \
|
||||||
{ \ \
|
{ \
|
||||||
if (mysqlnd_global_stats) { \
|
if (mysqlnd_global_stats) { \
|
||||||
my_uint64 v1 = (value1); \
|
my_uint64 v1 = (value1); \
|
||||||
my_uint64 v2 = (value2); \
|
my_uint64 v2 = (value2); \
|
||||||
|
|
|
@ -708,7 +708,7 @@ php_mysqlnd_ok_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
|
|
||||||
/* There is a message */
|
/* There is a message */
|
||||||
if (packet->header.size > p - buf && (i = php_mysqlnd_net_field_length(&p))) {
|
if (packet->header.size > p - buf && (i = php_mysqlnd_net_field_length(&p))) {
|
||||||
packet->message = estrndup((char *)p, MIN(i, sizeof(buf) - (p - buf)));
|
packet->message = pestrndup((char *)p, MIN(i, sizeof(buf) - (p - buf)), conn->persistent);
|
||||||
packet->message_len = i;
|
packet->message_len = i;
|
||||||
} else {
|
} else {
|
||||||
packet->message = NULL;
|
packet->message = NULL;
|
||||||
|
@ -906,7 +906,7 @@ php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
Thus, the name is size - 1. And we add 1 for a trailing \0.
|
Thus, the name is size - 1. And we add 1 for a trailing \0.
|
||||||
*/
|
*/
|
||||||
len = packet->header.size - 1;
|
len = packet->header.size - 1;
|
||||||
packet->info_or_local_file = emalloc(len + 1);
|
packet->info_or_local_file = pemalloc(len + 1, conn->persistent);
|
||||||
memcpy(packet->info_or_local_file, p, len);
|
memcpy(packet->info_or_local_file, p, len);
|
||||||
packet->info_or_local_file[len] = '\0';
|
packet->info_or_local_file[len] = '\0';
|
||||||
packet->info_or_local_file_len = len;
|
packet->info_or_local_file_len = len;
|
||||||
|
@ -920,7 +920,7 @@ php_mysqlnd_rset_header_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
p+=2;
|
p+=2;
|
||||||
/* Check for additional textual data */
|
/* Check for additional textual data */
|
||||||
if (packet->header.size > (p - buf) && (len = php_mysqlnd_net_field_length(&p))) {
|
if (packet->header.size > (p - buf) && (len = php_mysqlnd_net_field_length(&p))) {
|
||||||
packet->info_or_local_file = emalloc(len + 1);
|
packet->info_or_local_file = pemalloc(len + 1, conn->persistent);
|
||||||
memcpy(packet->info_or_local_file, p, len);
|
memcpy(packet->info_or_local_file, p, len);
|
||||||
packet->info_or_local_file[len] = '\0';
|
packet->info_or_local_file[len] = '\0';
|
||||||
packet->info_or_local_file_len = len;
|
packet->info_or_local_file_len = len;
|
||||||
|
@ -1574,7 +1574,7 @@ php_mysqlnd_stats_read(void *_packet, MYSQLND *conn TSRMLS_DC)
|
||||||
|
|
||||||
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, sizeof(buf), "statistics");
|
PACKET_READ_HEADER_AND_BODY(packet, conn, buf, sizeof(buf), "statistics");
|
||||||
|
|
||||||
packet->message = emalloc(packet->header.size + 1);
|
packet->message = pemalloc(packet->header.size + 1, conn->persistent);
|
||||||
memcpy(packet->message, buf, packet->header.size);
|
memcpy(packet->message, buf, packet->header.size);
|
||||||
packet->message[packet->header.size] = '\0';
|
packet->message[packet->header.size] = '\0';
|
||||||
packet->message_len = packet->header.size;
|
packet->message_len = packet->header.size;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue