nvmf/subsystem.c: add checks for valid utf-8 chars:
The NVMe spec states that nqn names are to be encoded in utf-8. The prefixes of all nqn's are already required to be ascii by virtue of their structure so they are already valid utf-8, but the user specified strings should be checked for valid utf-8 strings. Change-Id: I20090d366e93e98af4932eaa120d4edb6e512206 Signed-off-by: Seth Howell <seth.howell@intel.com> Reviewed-on: https://review.gerrithub.io/394118 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
0a97bd140b
commit
a1a47b5592
@ -44,6 +44,7 @@
|
||||
|
||||
#include "spdk_internal/bdev.h"
|
||||
#include "spdk_internal/log.h"
|
||||
#include "spdk_internal/utf.h"
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
@ -67,6 +68,7 @@ spdk_nvmf_valid_nqn(const char *nqn)
|
||||
size_t len;
|
||||
uuid_t uuid_value;
|
||||
uint i;
|
||||
int bytes_consumed;
|
||||
uint domain_label_length;
|
||||
char *reverse_domain_end;
|
||||
uint reverse_domain_end_index;
|
||||
@ -198,6 +200,17 @@ spdk_nvmf_valid_nqn(const char *nqn)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i = reverse_domain_end_index + 1;
|
||||
while (i < len) {
|
||||
bytes_consumed = utf8_valid(&nqn[i], &nqn[len]);
|
||||
if (bytes_consumed <= 0) {
|
||||
SPDK_ERRLOG("Invalid domain name in NQN \"%s\". Label names must contain only valid utf-8.\n", nqn);
|
||||
return false;
|
||||
}
|
||||
|
||||
i += bytes_consumed;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -323,6 +323,18 @@ nvmf_test_create_subsystem(void)
|
||||
CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
|
||||
spdk_nvmf_subsystem_destroy(subsystem);
|
||||
|
||||
/* Invalid name user string contains an invalid utf-8 character */
|
||||
strncpy(nqn, "nqn.2016-06.io.spdk:\xFFsubsystem1", sizeof(nqn));
|
||||
subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
|
||||
SPDK_CU_ASSERT_FATAL(subsystem == NULL);
|
||||
|
||||
/* Valid name with non-ascii but valid utf-8 characters */
|
||||
strncpy(nqn, "nqn.2016-06.io.spdk:\xe1\x8a\x88subsystem1\xca\x80", sizeof(nqn));
|
||||
subsystem = spdk_nvmf_subsystem_create(&tgt, nqn, SPDK_NVMF_SUBTYPE_NVME, 0);
|
||||
SPDK_CU_ASSERT_FATAL(subsystem != NULL);
|
||||
CU_ASSERT_STRING_EQUAL(subsystem->subnqn, nqn);
|
||||
spdk_nvmf_subsystem_destroy(subsystem);
|
||||
|
||||
/* Invalid uuid (too long) */
|
||||
strncpy(nqn, "nqn.2014-08.org.nvmexpress:uuid:11111111-aaaa-bbdd-FFEE-123456789abcdef",
|
||||
sizeof(nqn));
|
||||
|
Loading…
Reference in New Issue
Block a user