[PATCH] nvme: fix string_matches() helper
Christoph Hellwig
hch at lst.de
Tue Jun 13 06:07:09 PDT 2017
NVMe "ASCII" strings are not nul-terminated and can use up every single
byte in the field. Thus use strnlen to determine the match length instead
of possibly overrunning the field.
Signed-off-by: Christoph Hellwig <hch at lst.de>
---
drivers/nvme/host/core.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 434b18863895..2658a3a3cbb5 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1581,9 +1581,7 @@ static bool string_matches(const char *idstr, const char *match, size_t len)
if (!match)
return true;
- matchlen = strlen(match);
- WARN_ON_ONCE(matchlen > len);
-
+ matchlen = strnlen(match, len);
if (memcmp(idstr, match, matchlen))
return false;
--
2.11.0
More information about the Linux-nvme
mailing list