]> granicus.if.org Git - php/commitdiff
MySQLnd: Remove some unnecessary allocator failure checks
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 14 Dec 2020 10:58:43 +0000 (11:58 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 14 Dec 2020 10:58:43 +0000 (11:58 +0100)
emalloc/pemalloc are infallible.

ext/mysqlnd/mysqlnd_auth.c
ext/mysqlnd/mysqlnd_commands.c
ext/mysqlnd/mysqlnd_connection.c
ext/mysqlnd/mysqlnd_driver.c
ext/mysqlnd/mysqlnd_wireprotocol.c

index 81700ca86b2bd965f96878f260ebe9d1bb6ebc9f..e3a21dfae6abdd8885f79c77a0b4b63e9c88e28e 100644 (file)
@@ -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);
index 953c3a2fcd8366ac2bb83b6fa83052eaf130aa4b..57ac24b8c5eb1811c2d73f49f0d58cf7ad9860fb 100644 (file)
@@ -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);
index d034fb0ca3e4412b735b836e642df6457d7b716c..1c59c6ccde0be9e555ca7903a32fbb2c49a9887a 100644 (file)
@@ -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);
 }
index 4762d4e720dde8524faf08ec0ccda2b51ddd50bd..61a03fea29c744f7522c08bf2e320089318309c9 100644 (file)
@@ -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;
index 33a000d9a6b20fe491491950c80a5f8f6e3d231d..90b33d4bacab078250244deebaef00ecf4115a32 100644 (file)
@@ -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,