From: Martin George Date: Mon, 11 Apr 2022 04:06:20 +0000 (+0530) Subject: fabrics: avoid segfault when nvme discover fails with the -p option X-Git-Tag: v2.1-rc0~72^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=d49b74393cdbc29e7e092226083341bb9dfa8f6f;p=users%2Fsagi%2Fnvme-cli.git 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 --- 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;