From mboxrd@z Thu Jan 1 00:00:00 1970 From: lixiaokeng Subject: [PATCH 5/6] libmultipath: check udev* renturn value in get_ctrl_blkdev Date: Tue, 15 Sep 2020 12:41:41 +0800 Message-ID: <2e194628-4c9b-e259-f2b3-3c09e134575c@huawei.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Content-Language: en-GB To: Christophe Varoqui , Martin Wilck , Benjamin Marzinski , dm-devel mailing list Cc: linfeilong , "liuzhiqiang (I)" List-Id: dm-devel.ids We check return value of udev_device_get_devtype before dereference it. Signed-off-by:Lixiaokeng Signed-off-by: Zhiqiang Liu Signed-off-by: Linfeilong --- libmultipath/foreign/nvme.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libmultipath/foreign/nvme.c b/libmultipath/foreign/nvme.c index 0bc5106e..a0668713 100644 --- a/libmultipath/foreign/nvme.c +++ b/libmultipath/foreign/nvme.c @@ -538,6 +538,7 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx, struct udev_list_entry *item; struct udev_device *blkdev = NULL; struct udev_enumerate *enm = udev_enumerate_new(ctx->udev); + const char *devtype; if (enm == NULL) return NULL; @@ -562,7 +563,9 @@ struct udev_device *get_ctrl_blkdev(const struct context *ctx, udev_list_entry_get_name(item)); if (tmp == NULL) continue; - if (!strcmp(udev_device_get_devtype(tmp), "disk")) { + + devtype = udev_device_get_devtype(tmp); + if (!devtype && !strcmp(devtype, "disk")) { blkdev = tmp; break; } else --