]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
fabrics: avoid segfault if transport type is omitted
authorMartin George <marting@netapp.com>
Mon, 18 Apr 2022 07:22:37 +0000 (12:52 +0530)
committerMartin George <marting@netapp.com>
Mon, 18 Apr 2022 07:28:54 +0000 (12:58 +0530)
A nvme discover or connect-all would currently end up in a
segfault if the transport type is omitted as shown below:

nvme discover -w 192.168.1.114 -a 192.168.1.160
Segmentation fault (core dumped)

Avoid this segfault by checking if the transport type is
available before proceeding in get_default_trsvcid().

Signed-off-by: Martin George <marting@netapp.com>
fabrics.c

index f512ffabd081796130f050dbf8915955640be043..b55378595650cc2a5fdc18db7ae3dca78115bdac 100644 (file)
--- a/fabrics.c
+++ b/fabrics.c
@@ -478,6 +478,8 @@ static nvme_ctrl_t lookup_discover_ctrl(nvme_root_t r, struct tr_config *trcfg)
 static char *get_default_trsvcid(const char *transport,
                                 bool discovery_ctrl)
 {
+       if (!transport)
+               return NULL;
        if (!strcmp(transport, "tcp")) {
                if (discovery_ctrl) {
                        /* Default port for NVMe/TCP discovery controllers */