linux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn
authorMartin George <marting@netapp.com>
Thu, 11 Jan 2024 09:31:22 +0000 (15:01 +0530)
committerDaniel Wagner <wagi@monom.org>
Thu, 18 Jan 2024 13:36:38 +0000 (14:36 +0100)
Running nvme check-tls-key hits a segfault as seen below:

nvme check-tls-key
-d NVMeTLSkey-1:01:bB7soUnpHfxVg53sCY21KY3nLbqLit2RcIO8Rbdf3mKhcKaM:

Segmentation fault (core dumped)

This is because the strlen check on subsysnqn or hostnqn crashes at
src/nvme/linux.c due to either of them being null. Avoid this segfault
by checking these strings before running a strlen on them.

Signed-off-by: Martin George <marting@netapp.com>
src/nvme/linux.c

index 074c27e00a2d98b56f49de7294dbb3362196f63b..f072319318002c405a692a91da8d015218caa613 100644 (file)
@@ -1104,6 +1104,11 @@ static size_t nvme_identity_len(int hmac, int version, const char *hostnqn,
 {
        size_t len;
 
+       if (!hostnqn || !subsysnqn) {
+               errno = EINVAL;
+               return -1;
+       }
+
        len = strlen(hostnqn) + strlen(subsysnqn) + 12;
        if (version == 1) {
                len += 66;