From 90a7a924560281b8214cd14dbe850786ee70efb7 Mon Sep 17 00:00:00 2001 From: Krzysztof Karas Date: Wed, 1 Sep 2021 11:52:06 +0000 Subject: [PATCH] spdk_top: check thread ID before invoking pop-up from core pop-up This is to prevent app crashing when selecting a core with no threads and invoking threads pop-up. The thread ID is being checked before threads pop-up is displayed. (by default this value is set to 0, because valid thread IDs start from the value of 1). Fixes #2132 Change-Id: I2285370a41fa087c21f968d13882ad06e6577423 Signed-off-by: Krzysztof Karas Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9363 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Chengqiang Meng Reviewed-by: Tomasz Zawadzki --- app/spdk_top/spdk_top.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/spdk_top/spdk_top.c b/app/spdk_top/spdk_top.c index db681fee7..9580eb9a8 100644 --- a/app/spdk_top/spdk_top.c +++ b/app/spdk_top/spdk_top.c @@ -2068,7 +2068,7 @@ show_core(uint8_t current_page) uint64_t core_number = current_page * g_max_data_rows + g_selected_row; struct rpc_core_info *core_info = &g_cores_info[core_number]; uint64_t threads_count, i; - uint64_t thread_id; + uint64_t thread_id = 0; uint16_t current_threads_row; int c; char core_win_title[25]; @@ -2166,9 +2166,13 @@ show_core(uint8_t current_page) switch (c) { case 10: /* ENTER */ pthread_mutex_lock(&g_thread_lock); - thread_id = core_info->threads.thread[current_threads_row].id; + if (core_info->threads.threads_count > 0) { + thread_id = core_info->threads.thread[current_threads_row].id; + } pthread_mutex_unlock(&g_thread_lock); - show_single_thread(thread_id); + if (thread_id != 0) { + show_single_thread(thread_id); + } break; case 27: /* ESC */ stop_loop = true;