checker: add input check of state in checker_state_name func
PATCH 1/1 checker: add input check of state in checker_state_name func
In checker_state_name func, we donot check whether input i is valid. It may cause array access violation problem.
--- libmultipath/checkers.c | 26 +++++++++++++++----------- libmultipath/checkers.h | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-)
libmultipath/checkers.c +15 -11
@@ -22,23 +22,27 @@ struct checker_class {short msgtable_size; }; -char *checker_state_names[] = { -"wild" , -"unchecked" , -"down" , -"up" , -"shaky" , -"ghost" , -"pending" , -"timeout" , -"removed" , -"delayed" , +static const char *checker_state_names[PATH_MAX_STATE ] = { + [PATH_WILD ] ="wild" , + [PATH_UNCHECKED ] ="unchecked" , + [PATH_DOWN ] ="down" , + [PATH_UP ] ="up" , + [PATH_SHAKY ] ="shaky" , + [PATH_GHOST ] ="ghost" , + [PATH_PENDING ] ="pending" , + [PATH_TIMEOUT ] ="timeout" , + [PATH_REMOVED ] ="removed" , + [PATH_DELAYED ] ="delayed" , };static LIST_HEAD (checkers);const char *checker_state_name (int i) { +if (i <0 || i >=PATH_MAX_STATE ) { +condlog (2 ,"invalid state index = %d" , i); +return INVALID ; + }return checker_state_names[i]; }
libmultipath/checkers.h +2 -1
@@ -67,7 +67,7 @@* During this time, it is marked as "delayed" */ enum path_check_state { -PATH_WILD , +PATH_WILD =0 ,PATH_UNCHECKED ,PATH_DOWN ,PATH_UP ,
@@ -88,6 +88,7 @@ enum path_check_state {#define READSECTOR0 "readsector0"#define CCISS_TUR "cciss_tur"#define NONE "none" +#define INVALID "invalid"#define ASYNC_TIMEOUT_SEC 30
Signature · 1 line
2.24.0.windows.2
Quoted 9 lines · Zhiqiang Liu
In
checker_state_namefunc, we donot check whether input i is valid. It may cause array access violation problem.Signed-off-by Zhiqiang Liu <[email protected]>--- libmultipath/checkers.c | 26 +++++++++++++++----------- libmultipath/checkers.h | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-)
Thanks for the patch.
Btw, are you currently reviewing multipath-tools with coverity or some similar tool?
Martin
Quoted 11 lines · Martin Wilck
Quoted 9 lines · Zhiqiang Liu
In
checker_state_namefunc, we donot check whether input i is valid. It may cause array access violation problem.Signed-off-by Zhiqiang Liu <[email protected]>--- libmultipath/checkers.c | 26 +++++++++++++++----------- libmultipath/checkers.h | 3 ++- 2 files changed, 17 insertions(+), 12 deletions(-)
Quoted 8 lines
Reviewed-by Martin Wilck <[email protected]>Thanks for the patch.
Btw, are you currently reviewing multipath-tools with coverity or some similar tool?
Martin
Thanks for your reply.
Actually, I just read and learned multipath-tools code without using any tools. In the future, we may try to use some scanning tools for deep analysis.
Thanks for your review, again.