multipath-tools: coverity fixes
cover multipath-tools: coverity fixes
Martin Wilck (4):
libmpathcmd: check len parameter in mpath_recv_reply_data()
multipath-tools: use signed loop variable in vector_foreach_slot
libmpathutil: avoid size_t underflow in strchop()
fixup "libmultipath: use libmp_pathinfo() in update_multipath_table()"
libmpathcmd/mpath_cmd.c | 2 ++ libmpathutil/util.c | 4 ++-- libmultipath/structs_vec.c | 3 ++- multipathd/main.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/4 libmpathcmd: check len parameter in mpath_recv_reply_data()
Found by coverity. Callers check this parameter already, but the function is exported by libmpathcmd, so make sure we don't write '\0' to reply[-1].
--- libmpathcmd/mpath_cmd.c | 2 ++ 1 file changed, 2 insertions(+)
libmpathcmd/mpath_cmd.c +2 -0
@@ -170,6 +170,8 @@ int mpath_recv_reply_data(int fd, char *reply, size_t len, {ssize_t ret; +if (len <=0 ) +return 0 ; ret =read_all (fd, reply, len, timeout);if (ret <0 )return ret;
Signature · 1 line
2.45.2
PATCH 2/4 multipath-tools: use signed loop variable in vector_foreach_slot
In reply to Martin WilckIf we delete entries in the vector_foreach_slot loop, the loop index may underflow. It's not a big issue because we re-increment it in the next iteration and use a cast to int in the loop end condition, but it's cleaner to use an int here.
Found by coverity.
--- multipathd/main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
multipathd/main.c +5 -5
@@ -762,7 +762,7 @@ coalesce_maps(struct vectors *vecs, vector nmpv) {struct multipath * ompp;vector ompv = vecs->mpvec; -unsigned int i, reassign_maps; +int i, reassign_maps;struct config *conf; conf =get_multipath_config ();
@@ -1748,7 +1748,7 @@ static int map_discovery (struct vectors * vecs) {struct multipath * mpp; -unsigned int i; +int i;if (dm_get_maps (vecs->mpvec))return 1 ;
@@ -1970,7 +1970,7 @@ static void mpvec_garbage_collector (struct vectors * vecs) {struct multipath * mpp; -unsigned int i; +int i;if (!vecs->mpvec)return ;
@@ -2014,7 +2014,7 @@ static void missing_uev_wait_tick(struct vectors *vecs) {struct multipath * mpp; -unsigned int i; +int i;int timed_out =0 ; vector_foreach_slot (vecs->mpvec, mpp, i) {
@@ -2039,7 +2039,7 @@ static void ghost_delay_tick(struct vectors *vecs) {struct multipath * mpp; -unsigned int i; +int i; vector_foreach_slot (vecs->mpvec, mpp, i) {if (mpp->ghost_delay_tick <=0 )
Signature · 1 line
2.45.2
PATCH 3/4 libmpathutil: avoid size_t underflow in strchop()
In reply to Martin WilckFound by coverity.
--- libmpathutil/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
libmpathutil/util.c +2 -2
@@ -27,8 +27,8 @@ strchop(char *str) {size_t i; -for (i =strlen (str) -1 ; i != (size_t )-1 &&isspace (str[i]); i--) ; - str[++i] ='\0' ; +for (i =strlen (str); i !=0 &&isspace (str[i -1 ]); i--) ; + str[i] ='\0' ;return i; }
Signature · 1 line
2.45.2
PATCH 4/4 fixup "libmultipath: use libmp_pathinfo() in update_multipath_table()"
In reply to Martin WilckWe need to check for NULL before dereferencing mpp. Found by coverity.
--- libmultipath/structs_vec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
libmultipath/structs_vec.c +2 -1
@@ -504,11 +504,12 @@ update_multipath_table (struct multipath *mpp, vector pathvec, int flags)int r =DMP_ERR ;char __attribute__((cleanup (cleanup_charp))) *params =NULL ;char __attribute__((cleanup (cleanup_charp))) *status =NULL ; -unsigned long long size = mpp->size; +unsigned long long size;if (!mpp)return r; + size = mpp->size; r = libmp_mapinfo(DM_MAP_BY_NAME | MAPINFO_MPATH_ONLY, (mapid_t) { .str = mpp->alias }, (mapinfo_t) {
Signature · 1 line
2.45.2
On Thu, Jul 18, 2024 at 09:14:17PM +0200, Martin Wilck wrote:
For the set:
Quoted 14 lines
Martin Wilck (4):
libmpathcmd: check len parameter inmpath_recv_reply_data()
multipath-tools: use signed loop variable invector_foreach_slot
libmpathutil: avoidsize_tunderflow instrchop()
fixup "libmultipath: uselibmp_pathinfo()inupdate_multipath_table()"libmpathcmd/mpath_cmd.c | 2 ++ libmpathutil/util.c | 4 ++-- libmultipath/structs_vec.c | 3 ++- multipathd/main.c | 10 +++++----- 4 files changed, 11 insertions(+), 8 deletions(-)Signature · 1 line
2.45.2