[dm-devel] [PATCH]dm_get_map: fix segfault when can't found target
Wu Guanghao
wuguanghao3 at huawei.com
Fri May 27 02:27:37 UTC 2022
We got a segfault when we test multipath + iscsi.
(gdb) bt
#0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:74
#1 0x00007f694306cd23 in __GI___strdup (s=0x0) at strdup.c:41
#2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7",
size=size at entry=0x55d4bc0270d8, outparams=outparams at entry=0x7f6941add640) at devmapper.c:688
#3 0x00007f69433cbbdf in update_multipath_table (mpp=mpp at entry=0x55d4bc026f30,
pathvec=pathvec at entry=0x55d4bc063990, flags=flags at entry=0) at structs_vec.c:426
#4 0x00007f69433cbfe5 in update_multipath_strings (mpp=0x55d4bc026f30, pathvec=0x55d4bc063990)
at structs_vec.c:526
#5 0x000055d4bb52e03e in check_path (vecs=0x55d4bbfad760, pp=0x7f692402d270, ticks=<optimized out>)
at main.c:2280
#6 0x000055d4bb52f3e2 in checkerloop (ap=0x55d4bbfad760) at main.c:2542
#7 0x00007f694305b3ba in start_thread (arg=<optimized out>) at pthread_create.c:443
#8 0x00007f69430ddb40 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
(gdb) f 2
#2 0x00007f69433a147c in dm_get_map (name=0x55d4bc090320 "3600140537cde137ea8c43d8a971462c7",
size=size at entry=0x55d4bc0270d8, outparams=outparams at entry=0x7f6941add640) at devmapper.c:688
688 *outparams = strdup(params);
(gdb) l
683 *size = length;
684
685 if (!outparams)
686 r = DMP_OK;
687 else {
688 *outparams = strdup(params);
689 r = *outparams ? DMP_OK : DMP_ERR;
690 }
691
692 out:
(gdb) p params
$1 = 0x0
If can't found target, we should goto out
Signed-off-by: Wu Guanghao <wuguanghao3 at huawei.com>
---
libmultipath/devmapper.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 2507f77f..450b17ef 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -682,8 +682,8 @@ int dm_get_map(const char *name, unsigned long long *size, char **outparams)
r = DMP_NOT_FOUND;
/* Fetch 1st target */
if (dm_get_next_target(dmt, NULL, &start, &length,
- &target_type, ¶ms) != NULL)
- /* more than one target */
+ &target_type, ¶ms) != NULL || !params)
+ /* more than one target or not found target */
goto out;
if (size)
--
2.27.0
More information about the dm-devel
mailing list