From d49b74393cdbc29e7e092226083341bb9dfa8f6f Mon Sep 17 00:00:00 2001 From: Martin George Date: Mon, 11 Apr 2022 09:36:20 +0530 Subject: [PATCH] fabrics: avoid segfault when nvme discover fails with the -p option If the initial discovery controller creation fails while passing the -p option to the nvme discover (or connect-all) command, it could lead to the below segfault: nvme discover -t rdma -w 192.168.1.114 -a 192.168.1.113 -p Failed to write to /dev/nvme-fabrics: Connection reset by peer Segmentation fault (core dumped) Avoid this segfault by checking if the controller created in __create_discover_ctrl() is valid before proceeding. Signed-off-by: Martin George --- fabrics.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fabrics.c b/fabrics.c index 92c5312f..7439449d 100644 --- a/fabrics.c +++ b/fabrics.c @@ -174,6 +174,9 @@ static nvme_ctrl_t create_discover_ctrl(nvme_root_t r, nvme_host_t h, nvme_ctrl_t c; c = __create_discover_ctrl(r, h, cfg, trcfg); + if (!c) + return NULL; + if (!persistent) return c; -- 2.50.1