hw/block/nvme: assert namespaces array indices
commit3921756dee6dd7beb7b60167f368e8b981c77365
authorKlaus Jensen <k.jensen@samsung.com>
Mon, 15 Mar 2021 07:41:41 +0000 (15 08:41 +0100)
committerKlaus Jensen <k.jensen@samsung.com>
Thu, 18 Mar 2021 11:34:51 +0000 (18 12:34 +0100)
tree5e8ddb4daf444a5d2fa606852c35bcd4def0ef76
parent9c62f1efa854e66ebb0650d85918e4fecd3ec648
hw/block/nvme: assert namespaces array indices

Coverity complains about a possible memory corruption in the
nvme_ns_attach and _detach functions. While we should not (famous last
words) be able to reach this function without nsid having previously
been validated, this is still an open door for future misuse.

Make Coverity and maintainers happy by asserting that the index into the
array is valid. Also, while not detected by Coverity (yet), add an
assert in nvme_subsys_ns and nvme_subsys_register_ns as well since a
similar issue is exists there.

Fixes: 037953b5b299 ("hw/block/nvme: support namespace detach")
Fixes: CID 1450757
Fixes: CID 1450758
Cc: Minwoo Im <minwoo.im.dev@gmail.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
hw/block/nvme-subsys.c
hw/block/nvme-subsys.h
hw/block/nvme.h