From 4c2b7f3ac9052d50aa1c8fa20e643ce4bbf639c6 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 25 Jun 2022 20:07:08 +0800 Subject: [PATCH] tools/jlink-nuttx: Move the register index check to setget_reg avoid access tcbinfo before initializing it in update_tcbinfo Signed-off-by: Xiang Xiao --- tools/jlink-nuttx.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tools/jlink-nuttx.c b/tools/jlink-nuttx.c index bd47c19b54..f06e057d7b 100644 --- a/tools/jlink-nuttx.c +++ b/tools/jlink-nuttx.c @@ -252,6 +252,11 @@ static int setget_reg(struct plugin_priv_s *priv, uint32_t idx, { uint32_t regaddr; + if (regidx >= priv->tcbinfo->total_num) + { + return -EINVAL; + } + if (priv->tcbinfo->reg_offs[regidx] == UINT16_MAX) { if (write == 0) @@ -597,11 +602,6 @@ int RTOS_GetThreadReg(char *hexregval, uint32_t regindex, uint32_t threadid) return -ENOTSUP; } - if (regindex > g_plugin_priv.tcbinfo->total_num) - { - return -EINVAL; - } - idx = get_idx_from_pid(&g_plugin_priv, threadid); if (idx < 0) { @@ -670,11 +670,6 @@ int RTOS_SetThreadReg(char *hexregval, return -ENOTSUP; } - if (regindex > g_plugin_priv.tcbinfo->total_num) - { - return -EINVAL; - } - idx = get_idx_from_pid(&g_plugin_priv, threadid); if (idx < 0) {