From e53ae3ddfa0e0ca9857283c934d03304578545aa Mon Sep 17 00:00:00 2001 From: WillianChan Date: Thu, 2 Sep 2021 20:02:08 +0800 Subject: [PATCH] [modify][components][utilities]check if the ve_exporter_num is out of bounds. Signed-off-by: WillianChan --- components/utilities/var_export/var_export.c | 3 +++ components/utilities/var_export/var_export_cmd.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/components/utilities/var_export/var_export.c b/components/utilities/var_export/var_export.c index d90323edde..f4623dec04 100644 --- a/components/utilities/var_export/var_export.c +++ b/components/utilities/var_export/var_export.c @@ -69,6 +69,9 @@ int var_export_init(void) ve_exporter_table = (const ve_exporter_t *)ptr_begin; ve_exporter_num = (ptr_end - ptr_begin) / (sizeof(struct ve_exporter) / sizeof(unsigned int)) + 1; + /* check if the ve_exporter_num is out of bounds */ + RT_ASSERT(ve_exporter_num < (sizeof(ve_exporter_tab) / sizeof(ve_exporter_t))); + for (index_i = 0; index_i < ve_exporter_num; index_i++) { ve_exporter_tab[index_i] = ve_exporter_table[index_i]; diff --git a/components/utilities/var_export/var_export_cmd.c b/components/utilities/var_export/var_export_cmd.c index 85f43507f1..fba3cc92bb 100644 --- a/components/utilities/var_export/var_export_cmd.c +++ b/components/utilities/var_export/var_export_cmd.c @@ -67,7 +67,7 @@ static int ve_find_module(int argc, char **argv) exporter = ve_iter_next(&iter); if (exporter == RT_NULL) { - return RT_EOK; + return -RT_ERROR; } else { @@ -104,7 +104,7 @@ static int ve_find_value(int argc, char **argv) exporter = ve_iter_next(&iter); if (exporter == RT_NULL) { - return RT_EOK; + return -RT_ERROR; } else {