From 0542abcee974a47c8afb0fcfe5ebf282f674ac8b Mon Sep 17 00:00:00 2001 From: Dmytro Podgornyi Date: Fri, 26 Apr 2024 17:57:41 +0300 Subject: [PATCH] issue: 3928407 Remove VLAs to fix clang-18 build clang-18 generates a warning that VLA is a clang extension. Allocate the arrays on heap instead of stack. Signed-off-by: Dmytro Podgornyi --- src/core/dev/net_device_table_mgr.cpp | 2 +- src/core/dev/ring_tap.cpp | 11 ++++++++--- src/core/sock/sockinfo_tcp.cpp | 21 +++++++++++++-------- src/core/sock/sockinfo_udp.cpp | 11 +++++++++-- src/core/util/utils.cpp | 2 +- src/stats/stats_reader.cpp | 8 ++++++-- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/core/dev/net_device_table_mgr.cpp b/src/core/dev/net_device_table_mgr.cpp index 65a8118d7..77ab7dadb 100644 --- a/src/core/dev/net_device_table_mgr.cpp +++ b/src/core/dev/net_device_table_mgr.cpp @@ -466,7 +466,7 @@ void net_device_table_mgr::global_ring_wait_for_notification_and_process_element uint64_t *p_poll_sn, void *pv_fd_ready_array /*=NULL*/) { ndtm_logfunc(""); - int max_fd = 16; + constexpr int max_fd = 16; struct epoll_event events[max_fd]; int res = SYSCALL(epoll_wait, global_ring_epfd_get(), events, max_fd, 0); diff --git a/src/core/dev/ring_tap.cpp b/src/core/dev/ring_tap.cpp index 2e7295652..d1ee73791 100644 --- a/src/core/dev/ring_tap.cpp +++ b/src/core/dev/ring_tap.cpp @@ -597,20 +597,25 @@ int ring_tap::mem_buf_tx_release(mem_buf_desc_t *buff_list, bool b_accounting, b int ring_tap::send_buffer(xlio_ibv_send_wr *wr, xlio_wr_tx_packet_attr attr) { - int ret = 0; - iovec iovec[wr->num_sge]; NOT_IN_USE(attr); + struct iovec *iovec = new struct iovec[wr->num_sge]; + if (!iovec) { + errno = ENOMEM; + return -1; + } + for (int i = 0; i < wr->num_sge; i++) { iovec[i].iov_base = (void *)wr->sg_list[i].addr; iovec[i].iov_len = wr->sg_list[i].length; } - ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge); + int ret = SYSCALL(writev, m_tap_fd, iovec, wr->num_sge); if (ret < 0) { ring_logdbg("writev: tap_fd %d, errno: %d\n", m_tap_fd, errno); } + delete[] iovec; return ret; } diff --git a/src/core/sock/sockinfo_tcp.cpp b/src/core/sock/sockinfo_tcp.cpp index cba406023..0e30b68d1 100644 --- a/src/core/sock/sockinfo_tcp.cpp +++ b/src/core/sock/sockinfo_tcp.cpp @@ -2207,15 +2207,20 @@ err_t sockinfo_tcp::rx_lwip_cb_recv_callback(void *arg, struct tcp_pcb *pcb, str } // fill io vector array with data buffer pointers - iovec iov[p_first_desc->rx.n_frags]; - nr_frags = 0; - for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) { - iov[nr_frags++] = tmp->rx.frag; - } + struct iovec *iov = new struct iovec[p_first_desc->rx.n_frags]; + if (likely(iov)) { + nr_frags = 0; + for (tmp = p_first_desc; tmp; tmp = tmp->p_next_desc) { + iov[nr_frags++] = tmp->rx.frag; + } - // call user callback - callback_retval = - conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info, conn->m_rx_callback_context); + // call user callback + callback_retval = conn->m_rx_callback(conn->m_fd, nr_frags, iov, &pkt_info, + conn->m_rx_callback_context); + delete[] iov; + } else { + callback_retval = XLIO_PACKET_DROP; + } } if (callback_retval == XLIO_PACKET_DROP) { diff --git a/src/core/sock/sockinfo_udp.cpp b/src/core/sock/sockinfo_udp.cpp index 521baa109..b1f79d416 100644 --- a/src/core/sock/sockinfo_udp.cpp +++ b/src/core/sock/sockinfo_udp.cpp @@ -2305,15 +2305,22 @@ inline xlio_recv_callback_retval_t sockinfo_udp::inspect_by_user_cb(mem_buf_desc } // fill io vector array with data buffer pointers - iovec iov[p_desc->rx.n_frags]; int nr_frags = 0; + struct iovec *iov = new struct iovec[p_desc->rx.n_frags]; + if (!iov) { + return XLIO_PACKET_DROP; + } for (mem_buf_desc_t *tmp = p_desc; tmp; tmp = tmp->p_next_desc) { iov[nr_frags++] = tmp->rx.frag; } // call user callback - return m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context); + xlio_recv_callback_retval_t ret = + m_rx_callback(m_fd, nr_frags, iov, &pkt_info, m_rx_callback_context); + + delete[] iov; + return ret; } /* Update completion with diff --git a/src/core/util/utils.cpp b/src/core/util/utils.cpp index 487b6d9a9..17afd431c 100644 --- a/src/core/util/utils.cpp +++ b/src/core/util/utils.cpp @@ -150,7 +150,7 @@ int get_base_interface_name(const char *if_name, char *base_ifname, size_t sz_ba } } - unsigned char tmp_mac[ADDR_LEN]; + unsigned char tmp_mac[MAX_L2_ADDR_LEN]; if (ADDR_LEN == get_local_ll_addr(ifa->ifa_name, tmp_mac, ADDR_LEN, false)) { int size_to_compare = 0; if (ADDR_LEN == ETH_ALEN) { diff --git a/src/stats/stats_reader.cpp b/src/stats/stats_reader.cpp index 08e50e2e0..366c69a49 100644 --- a/src/stats/stats_reader.cpp +++ b/src/stats/stats_reader.cpp @@ -2301,9 +2301,12 @@ void get_all_processes_pids(std::vector &pids) int print_processes_stats(const std::vector &pids) { const int SIZE = pids.size(); - int num_instances = 0; - sh_mem_info_t sh_mem_info[SIZE]; + + sh_mem_info_t *sh_mem_info = new sh_mem_info_t[SIZE]; + if (!sh_mem_info) { + return 1; + } // 1. N * prepare shmem and indicate XLIO to update shmem for (int i = 0; i < SIZE; ++i) { @@ -2323,6 +2326,7 @@ int print_processes_stats(const std::vector &pids) complete_print_process_stats(sh_mem_info[i]); } + delete[] sh_mem_info; return 0; }