com php-src: MySQLnd: Remove some unnecessary allocator failure checks: ext/mysqlnd/mysqlnd_auth.c ext/mysqlnd/mysqlnd_commands .c
ext/mysqlnd/mysqlnd_connection.c ext/mysqlnd/mysql nd_driver.c ext/mysqlnd/mysqlnd_wireprotocol.c
| From: | Nikita Popov | Date: | Mon, 14 Dec 2020 10:58:43 +0000 |
| Subject: | com php-src: MySQLnd: Remove some unnecessary allocator failure checks: ext/mysqlnd/mysqlnd_auth.c ext/mysqlnd/mysqlnd_commands .c ext/mysqlnd/mysqlnd_connection.c ext/mysqlnd/mysql nd_driver.c ext/mysqlnd/mysqlnd_wireprotocol.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114432@lists.php.net to get a copy of this message | ||
Commit: 5d9bd14ccc914301e39fd97015a26e8015918e05
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 14 Dec 2020 11:58:43 +0100
Parents: 86e317ad80a0b676215775245486f39d9d364458
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=5d9bd14ccc914301e39fd97015a26e8015918e05
Log:
MySQLnd: Remove some unnecessary allocator failure checks
emalloc/pemalloc are infallible.
Changed paths:
M ext/mysqlnd/mysqlnd_auth.c
M ext/mysqlnd/mysqlnd_commands..c
M ext/mysqlnd/mysqlnd_connection.c
M ext/mysqlnd/mysqlnd_driver.c
M ext/mysqlnd/mysqlnd_wireprotocol.c
Diff:
diff --git a/ext/mysqlnd/mysqlnd_auth.c b/ext/mysqlnd/mysqlnd_auth.c
index 81700ca86b2...e3a21dfae6a 100644
--- a/ext/mysqlnd/mysqlnd_auth.c
+++ b/ext/mysqlnd/mysqlnd_auth.c
@@ -103,10 +103,6 @@ mysqlnd_run_authentication(
}
conn->authentication_plugin_data.l = plugin_data_len;
conn->authentication_plugin_data.s = mnd_pemalloc(conn->authentication_plugin_data.l,
conn->persistent);
- if (!conn->authentication_plugin_data.s) {
- SET_OOM_ERROR(conn->error_info);
- goto end;
- }
memcpy(conn->authentication_plugin_data.s, plugin_data, plugin_data_len);
DBG_INF_FMT("salt(%d)=[%.*s]", plugin_data_len, plugin_data_len, plugin_data);
diff --git a/ext/mysqlnd/mysqlnd_commands.c b/ext/mysqlnd/mysqlnd_commands.c
index 953c3a2fcd8..57ac24b8c5e 100644
--- a/ext/mysqlnd/mysqlnd_commands.c
+++ b/ext/mysqlnd/mysqlnd_commands.c
@@ -112,11 +112,6 @@ MYSQLND_METHOD(mysqlnd_command, init_db)(MYSQLND_CONN_DATA * const conn, const
M
}
conn->connect_or_select_db.s = mnd_pestrndup(db.s, db.l, conn->persistent);
conn->connect_or_select_db.l = db.l;
- if (!conn->connect_or_select_db.s) {
- /* OOM */
- SET_OOM_ERROR(conn->error_info);
- ret = FAIL;
- }
}
DBG_RETURN(ret);
diff --git a/ext/mysqlnd/mysqlnd_connection.c b/ext/mysqlnd/mysqlnd_connection.c
index d034fb0ca3e..1c59c6ccde0 100644
--- a/ext/mysqlnd/mysqlnd_connection.c
+++ b/ext/mysqlnd/mysqlnd_connection.c
@@ -709,17 +709,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
conn->connect_or_select_db.l = database.l;
conn->connect_or_select_db.s = mnd_pestrndup(database.s, conn->connect_or_select_db.l,
conn->persistent);
- if (!conn->username.s || !conn->password.s|| !conn->connect_or_select_db.s) {
- SET_OOM_ERROR(conn->error_info);
- goto err; /* OOM */
- }
-
if (!unix_socket && !named_pipe) {
conn->hostname..s = mnd_pestrndup(hostname.s, hostname.l, conn->persistent);
- if (!conn->hostname.s) {
- SET_OOM_ERROR(conn->error_info);
- goto err; /* OOM */
- }
conn->hostname.l = hostname.l;
{
char *p;
@@ -730,10 +721,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
}
conn->host_info = mnd_pestrdup(p, conn->persistent);
mnd_sprintf_free(p);
- if (!conn->host_info) {
- SET_OOM_ERROR(conn->error_info);
- goto err; /* OOM */
- }
}
} else {
conn->unix_socket.s = mnd_pestrdup(socket_or_pipe.s, conn->persistent);
@@ -746,12 +733,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, connect)(MYSQLND_CONN_DATA * conn,
SET_OOM_ERROR(conn->error_info);
goto err; /* OOM */
}
- conn->host_info = mnd_pestrdup(p, conn->persistent);
+ conn->host_info = mnd_pestrdup(p, conn->persistent);
mnd_sprintf_free(p);
- if (!conn->host_info) {
- SET_OOM_ERROR(conn->error_info);
- goto err; /* OOM */
- }
} else {
php_error_docref(NULL, E_WARNING, "Impossible. Should be either socket or a pipe. Report a
bug!");
}
@@ -1672,14 +1655,8 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA *
const c
/* when num_commands is 0, then realloc will be effectively a malloc call, internally */
/* Don't assign to conn->options->init_commands because in case of OOM we will lose
the pointer and leak */
new_init_commands = mnd_perealloc(conn->options->init_commands, sizeof(char *) *
(conn->options->num_commands + 1), conn->persistent);
- if (!new_init_commands) {
- goto oom;
- }
conn->options->init_commands = new_init_commands;
new_command = mnd_pestrdup(value, conn->persistent);
- if (!new_command) {
- goto oom;
- }
conn->options->init_commands[conn->options->num_commands] = new_command;
++conn->options->num_commands;
break;
@@ -1702,9 +1679,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const
c
}
new_charset_name = mnd_pestrdup(value, conn->persistent);
- if (!new_charset_name) {
- goto oom;
- }
if (conn->options->charset_name) {
mnd_pefree(conn->options->charset_name, conn->persistent);
}
@@ -1740,9 +1714,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const
c
case MYSQLND_OPT_AUTH_PROTOCOL:
{
char * new_auth_protocol = value? mnd_pestrdup(value, conn->persistent) : NULL;
- if (value && !new_auth_protocol) {
- goto oom;
- }
if (conn->options->auth_protocol) {
mnd_pefree(conn->options->auth_protocol, conn->persistent);
}
@@ -1781,9 +1752,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option)(MYSQLND_CONN_DATA * const
c
}
conn->m->local_tx_end(conn, this_func, ret);
DBG_RETURN(ret);
-oom:
- SET_OOM_ERROR(conn->error_info);
- conn->m->local_tx_end(conn, this_func, FAIL);
end:
DBG_RETURN(FAIL);
}
@@ -1811,9 +1779,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA *
cons
if (!conn->options->connect_attr) {
DBG_INF("Initializing connect_attr hash");
conn->options->connect_attr = mnd_pemalloc(sizeof(HashTable), conn->persistent);
- if (!conn->options->connect_attr) {
- goto oom;
- }
zend_hash_init(conn->options->connect_attr, 0, NULL, conn->persistent ?
ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR, conn->persistent);
}
DBG_INF_FMT("Adding [%s][%s]", key, value);
@@ -1839,9 +1804,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, set_client_option_2d)(MYSQLND_CONN_DATA *
cons
}
conn->m->local_tx_end(conn, this_func, ret);
DBG_RETURN(ret);
-oom:
- SET_OOM_ERROR(conn->error_info);
- conn->m->local_tx_end(conn, this_func, FAIL);
end:
DBG_RETURN(FAIL);
}
diff --git a/ext/mysqlnd/mysqlnd_driver.c b/ext/mysqlnd/mysqlnd_driver.c
index 4762d4e720d..61a03fea29c 100644
--- a/ext/mysqlnd/mysqlnd_driver.c
+++ b/ext/mysqlnd/mysqlnd_driver.c
@@ -192,16 +192,10 @@ MYSQLND_METHOD(mysqlnd_object_factory,
get_prepared_statement)(MYSQLND_CONN_DATA
DBG_ENTER("mysqlnd_object_factory::get_prepared_statement");
do {
- if (!ret) {
- break;
- }
ret->m = mysqlnd_stmt_get_methods();
stmt = ret->data = mnd_ecalloc(1, sizeof(MYSQLND_STMT_DATA));
DBG_INF_FMT("stmt=%p", stmt);
- if (!stmt) {
- break;
- }
if (FAIL == mysqlnd_error_info_init(&stmt->error_info_impl, 0)) {
break;
diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c
index 33a000d9a6b..90b33d4baca 100644
--- a/ext/mysqlnd/mysqlnd_wireprotocol.c
+++ b/ext/mysqlnd/mysqlnd_wireprotocol.c
@@ -1074,14 +1074,9 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet)
*/
len = packet->header.size - 1;
packet->info_or_local_file.s = mnd_emalloc(len + 1);
- if (packet->info_or_local_file.s) {
- memcpy(packet->info_or_local_file.s, p, len);
- packet->info_or_local_file.s[len] = '\0';
- packet->info_or_local_file.l = len;
- } else {
- SET_OOM_ERROR(error_info);
- ret = FAIL;
- }
+ memcpy(packet->info_or_local_file.s, p, len);
+ packet->info_or_local_file.s[len] = '\0';
+ packet->info_or_local_file.l = len;
break;
case 0x00:
DBG_INF("UPSERT");
@@ -1101,14 +1096,9 @@ php_mysqlnd_rset_header_read(MYSQLND_CONN_DATA * conn, void * _packet)
/* Check for additional textual data */
if (packet->header.size > (size_t) (p - buf) && (len =
php_mysqlnd_net_field_length(&p))) {
packet->info_or_local_file.s = mnd_emalloc(len + 1);
- if (packet->info_or_local_file.s) {
- memcpy(packet->info_or_local_file.s, p, len);
- packet->info_or_local_file.s[len] = '\0';
- packet->info_or_local_file.l = len;
- } else {
- SET_OOM_ERROR(error_info);
- ret = FAIL;
- }
+ memcpy(packet->info_or_local_file..s, p, len);
+ packet->info_or_local_file.s[len] = '\0';
+ packet->info_or_local_file.l = len;
}
DBG_INF_FMT("affected_rows=%llu last_insert_id=%llu server_status=%u
warning_count=%u",
packet->affected_rows, packet->last_insert_id,