Skip to content

Commit

Permalink
issue: 3848340 Coverity Supress FalsePositives
Browse files Browse the repository at this point in the history
Suppress irrelevant and false positive Coveritywarnings
in various files using comments
Turn off Coverity checks for sum of null dereference
overflow, missing lock, assigned pointer, copy assignment call
and other identified issues

Signed-off-by: Bashar Abdelgafer  <babdelgafer@nvidia.com>
  • Loading branch information
BasharRadya committed Jul 10, 2024
1 parent d7f97e0 commit edfdf0a
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/core/dev/ring_allocation_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ int cpu_manager::reserve_cpu_for_thread(pthread_t tid, int suggested_cpu /* = NO
cpu = suggested_cpu;
}
CPU_ZERO(&cpu_set);
// coverity[overflow_const:FALSE] /*Turn off coverity check, cpu value is non-negative*/
CPU_SET(cpu, &cpu_set);
__log_dbg("Attach tid=%lu running on cpu=%d to cpu=%d", tid, sched_getcpu(), cpu);
ret = pthread_setaffinity_np(tid, sizeof(cpu_set_t), &cpu_set);
Expand Down
1 change: 1 addition & 0 deletions src/core/dev/ring_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ int ring_simple::socketxtreme_poll(struct xlio_socketxtreme_completion_t *xlio_c
bool do_poll = true;

if (likely(xlio_completions) && ncompletions) {
// coverity[missing_lock:FALSE] /*Turn off coverity missing_lock check*/
if ((flags & SOCKETXTREME_POLL_TX) && !m_socketxtreme.ec_sock_list_start) {
uint64_t poll_sn = 0;
const std::lock_guard<decltype(m_lock_ring_tx)> lock(m_lock_ring_tx);
Expand Down
1 change: 1 addition & 0 deletions src/core/event/delta_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void timer::remove_all_timers(timer_handler *handler)
remove_from_list(node_tmp);
// Remove & Free node
free(node_tmp);
// coverity[assigned_pointer:FALSE] /* Turn off coverity check,intended assign*/
node_tmp = nullptr;
} else {
node = node->next;
Expand Down
1 change: 1 addition & 0 deletions src/core/lwip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
pcb->rcv_ann_right_edge + LWIP_MIN((pcb->rcv_wnd_max / 2), pcb->mss))) {
/* we can advertise more window */
pcb->rcv_ann_wnd = pcb->rcv_wnd;
// coverity[overflow:FALSE] /* Turn off coverity check, value is non-negative */
return new_right_edge - pcb->rcv_ann_right_edge;
} else {
if (TCP_SEQ_GT(pcb->rcv_nxt, pcb->rcv_ann_right_edge)) {
Expand Down
1 change: 1 addition & 0 deletions src/core/proto/neighbour_table_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void neigh_table_mgr::notify_cb(event *ev)

// find all neigh entries with an appropriate peer_ip and net_device
if (p_ndev) {
// coverity[copy_constructor_call:FALSE] /*Turn off check COPY_INSTEAD_OF_MOVE*/
neigh_entry *p_ne = dynamic_cast<neigh_entry *>(get_entry(neigh_key(addr, p_ndev)));
if (p_ne) {
// Call the relevant neigh_entry to handle the event
Expand Down
1 change: 1 addition & 0 deletions src/core/sock/fd_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ int fd_collection::add_cq_channel_fd(int cq_ch_fd, ring *p_ring)
fdcoll_logwarn("cq channel fd already exists in fd_collection");
m_p_cq_channel_map[cq_ch_fd] = nullptr;
delete p_cq_ch_info;
// coverity[assigned_pointer] /* Turn off coverity check, intended assign*/
p_cq_ch_info = nullptr;
}
BULLSEYE_EXCLUDE_BLOCK_END
Expand Down
6 changes: 4 additions & 2 deletions src/core/sock/sockinfo_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,7 @@ ssize_t sockinfo_tcp::rx(const rx_call_t call_type, iovec *p_iov, ssize_t sz_iov
* error notification without data processing
*/
if (__msg && __msg->msg_control && (in_flags & MSG_ERRQUEUE)) {
// coverity[MISSING_LOCK:FALSE] /*Turn off coverity check for missing lock*/
if (m_error_queue.empty()) {
errno = EAGAIN;
unlock_tcp_con();
Expand Down Expand Up @@ -2873,6 +2874,7 @@ int sockinfo_tcp::bind(const sockaddr *__addr, socklen_t __addrlen)
UNLOCK_RET(-1);
}
m_pcb.is_ipv6 = (addr.get_sa_family() == AF_INET6);
// coverity[copy_assignment_call:FALSE] /*Turn off coverity check for COPY_INSTEAD_OF_MOVE*/
m_bound = addr;

if (!m_bound.is_anyaddr() &&
Expand Down Expand Up @@ -4047,7 +4049,6 @@ bool sockinfo_tcp::is_writeable()
__log_funcall("--->>> tcp_sndbuf(&m_pcb)=%ld", sndbuf_available());
return true;
}

bool sockinfo_tcp::is_errorable(int *errors)
{
*errors = 0;
Expand All @@ -4056,7 +4057,7 @@ bool sockinfo_tcp::is_errorable(int *errors)
m_conn_state == TCP_CONN_RESETED || m_conn_state == TCP_CONN_FAILED) {
*errors |= POLLHUP;
}

// coverity[MISSING_LOCK:FALSE] /*Turn off coverity check for missing lock*/
if ((m_conn_state == TCP_CONN_ERROR) || (!m_error_queue.empty())) {
*errors |= POLLERR;
}
Expand Down Expand Up @@ -4564,6 +4565,7 @@ int sockinfo_tcp::tcp_setsockopt(int __level, int __optname, __const void *__opt
ret = -1;
break;
} else {
// coverity[copy_assignment_call:FALSE] /*Turn off coverity COPY_INSTEAD_OF_MOVE*/
m_so_bindtodevice_ip = addr;

si_tcp_logdbg("SOL_SOCKET, %s='%s' (%s)", setsockopt_so_opt_to_str(__optname),
Expand Down
5 changes: 5 additions & 0 deletions src/core/sock/sockinfo_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ int sockinfo_udp::setsockopt(int __level, int __optname, __const void *__optval,
} else if (!get_ip_addr_from_ifname((char *)__optval, addr, m_family) ||
(m_family == AF_INET6 && !m_is_ipv6only &&
!get_ip_addr_from_ifname((char *)__optval, addr, AF_INET))) {
// coverity[copy_assignment_call:FALSE] /*Turn off check COPY_INSTEAD_OF_MOVE*/
m_so_bindtodevice_ip = addr;
} else {
si_udp_logdbg("SOL_SOCKET, %s=\"???\" - NOT HANDLED, cannot find if_name",
Expand Down Expand Up @@ -1331,6 +1332,7 @@ int sockinfo_udp::setsockopt(int __level, int __optname, __const void *__optval,
} else {
ip_addr src_addr {0};
if (get_ip_addr_from_ifindex(if_ix, src_addr, AF_INET6) == 0) {
// coverity[copy_assignment_call:FALSE] /*Turn off check COPY_INSTEAD_OF_MOVE*/
m_mc_tx_src_ip = src_addr;
} else {
si_udp_logdbg("IPPROTO_IPV6, setsockopt(%s) will be passed to OS for "
Expand Down Expand Up @@ -1554,6 +1556,7 @@ int sockinfo_udp::resolve_if_ip(const int if_index, const ip_address &ip, ip_add
} else {
ip_addr src_addr {0};
if (get_ip_addr_from_ifindex(if_index, src_addr, m_family) == 0) {
// coverity[copy_assignment_call:FALSE] /*Turn off check COPY_INSTEAD_OF_MOVE*/
resolved_ip = src_addr;
} else {
si_udp_logdbg("Can't find interface IP of interface index %d", if_index);
Expand Down Expand Up @@ -2117,6 +2120,7 @@ ssize_t sockinfo_udp::tx(xlio_tx_call_attr_t &tx_arg)
// Fast path
// We found our target dst_entry object
m_p_last_dst_entry = p_dst_entry = dst_entry_iter->second;
// coverity[copy_assignment_call:FALSE] /*Turn off check COPY_INSTEAD_OF_MOVE*/
m_last_sock_addr = dst;
} else {
// Slow path
Expand Down Expand Up @@ -2530,6 +2534,7 @@ bool sockinfo_udp::rx_input_cb(mem_buf_desc_t *p_desc, void *pv_fd_ready_array)
m_port_map.erase(std::remove(m_port_map.begin(), m_port_map.end(),
m_port_map[m_port_map_index].port));
if (m_port_map_index) {
// coverity[underflow:FALSE] /*Turn off coverity check for underflow*/
m_port_map_index--;
}
m_port_map_lock.unlock();
Expand Down
1 change: 1 addition & 0 deletions src/core/util/hugepage_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ size_t hugepage_mgr::read_meminfo(const char *tag)
}
infile.close();
}
// coverity[return_overflow:FALSE] /*Turn off coverity check for overflow*/
return val;
}

Expand Down
2 changes: 2 additions & 0 deletions src/stats/stats_data_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct tls_context_counters_show {
tls_context_counters_show &update(const ring_instance_block_t (&rings)[NUM_OF_SUPPORTED_RINGS])
{
auto count_if_enabled = [](tls_contxts_num &val, const ring_instance_block_t &ring_stat) {
// coverity[missing_lock:FALSE] /* Turn off coverity missing_lock check*/
if (ring_stat.b_enabled) {
val.tx += ring_stat.ring_stats.n_tx_tls_contexts;
val.rx += ring_stat.ring_stats.n_rx_tls_contexts;
Expand Down Expand Up @@ -240,6 +241,7 @@ struct ring_packet_aggregate {
ring_packet_aggregate &update(const ring_instance_block_t (&rings)[NUM_OF_SUPPORTED_RINGS])
{
auto count_if_enabled = [](pkt_cnt &val, const ring_instance_block_t &ring_stat) {
// coverity[missing_lock:FALSE] /* Turn off coverity missing_lock check*/
if (ring_stat.b_enabled) {
val.tx += ring_stat.ring_stats.n_tx_pkt_count;
val.rx += ring_stat.ring_stats.n_rx_pkt_count;
Expand Down
5 changes: 5 additions & 0 deletions src/stats/stats_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ void print_ring_stats(ring_instance_block_t *p_ring_inst_arr)
}

for (int i = 0; i < NUM_OF_SUPPORTED_RINGS; i++) {
// coverity[missing_lock:FALSE] /* Turn off coverity missing_lock check*/
if (p_ring_inst_arr[i].b_enabled) {
p_ring_stats = &p_ring_inst_arr[i].ring_stats;
printf("======================================================\n");
Expand Down Expand Up @@ -575,6 +576,7 @@ void print_cq_stats(cq_instance_block_t *p_cq_inst_arr)
}

for (int i = 0; i < NUM_OF_SUPPORTED_CQS; i++) {
// coverity[missing_lock:FALSE] /* Turn off coverity missing_lock check*/
if (p_cq_inst_arr[i].b_enabled) {
p_cq_stats = &p_cq_inst_arr[i].cq_stats;
printf("======================================================\n");
Expand Down Expand Up @@ -628,6 +630,7 @@ void print_bpool_stats(bpool_instance_block_t *p_bpool_inst_arr)
}

for (int i = 0; i < NUM_OF_SUPPORTED_BPOOLS; i++) {
// coverity[missing_lock:FALSE] /* Turn off coverity missing_lock check*/
if (p_bpool_inst_arr && p_bpool_inst_arr[i].b_enabled) {
p_bpool_stats = &p_bpool_inst_arr[i].bpool_stats;
printf("======================================================\n");
Expand Down Expand Up @@ -1191,6 +1194,7 @@ void add_fd_to_array(int fd, ip_addr mc_grp, mc_group_fds_t *mc_group_fds, int *
}
// the mc_group wasnt found
// Add this mc group to the array
// coverity[copy_assignment_call] /* Turn off coverity warning for COPY_INSTEAD_OF_MOVE */
mc_group_fds[i].mc_grp = mc_grp;
int fd1 = fd;
mc_group_fds[i].fd_list.push_back(fd1);
Expand Down Expand Up @@ -1231,6 +1235,7 @@ void show_mc_group_stats(mc_grp_info_t *p_mc_grp_info, socket_instance_block_t *
size_t fd = (size_t)p_instance[i].skt_stats.fd;
if (p_instance[i].b_enabled && g_fd_mask[fd]) {
socket_stats_t *p_si_stats = &p_instance[i].skt_stats;
// coverity[missing_lock] /* Turn off coverity missing_lock check*/
for (int grp_idx = 0; grp_idx < p_mc_grp_info->max_grp_num; grp_idx++) {
if (p_si_stats->mc_grp_map.test(grp_idx)) {
add_fd_to_array(p_si_stats->fd, p_mc_grp_info->mc_grp_tbl[grp_idx].mc_grp,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/lock_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ class lock_spin_recursive : public lock_spin {
m_owner = m_invalid_owner;
};
~lock_spin_recursive() {};

inline int lock()
{
DEFINED_NO_THREAD_LOCK_RETURN_0
pthread_t self = pthread_self();
/* coverity[use_same_locks_for_read_and_modify:FALSE] */
if (m_owner == self) {
++m_lock_count;
return 0;
Expand Down Expand Up @@ -386,11 +386,11 @@ class lock_mutex_recursive : public lock_mutex {
m_owner = m_invalid_owner;
};
~lock_mutex_recursive() {};

inline int lock()
{
DEFINED_NO_THREAD_LOCK_RETURN_0
pthread_t self = pthread_self();
/* coverity[use_same_locks_for_read_and_modify:FALSE] */
if (m_owner == self) {
++m_lock_count;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion tools/daemon/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ ssize_t sys_sendto(int sockfd, const void *buf, size_t len, int flags,
data += n;
nb += n;
} while (!(flags & MSG_DONTWAIT) && (len > 0));

// coverity[return_overflow:FALSE] /*Turn off coverity check for overflow*/
return nb;
}

Expand Down
1 change: 1 addition & 0 deletions tools/daemon/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,7 @@ static int proc_fanotify(void *buffer, int nbyte)
}

/* Close the file descriptor of the event */
// coverity[double_close:FALSE] /* Turn off coverity check*/
close(data->fd);
data = FAN_EVENT_NEXT(data, len);
}
Expand Down

0 comments on commit edfdf0a

Please sign in to comment.