Skip to content

Commit

Permalink
linux: avoid segfault in check-tls-key due to null hostnqn/subsysnqn
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
martin-gpy authored and igaw committed Jan 18, 2024
1 parent 11d0a89 commit f46b064
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/nvme/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f46b064

Please sign in to comment.