From f505ac2e8a4ed59794b9e316ac45f0e822b988f3 Mon Sep 17 00:00:00 2001 From: Alex Reid Date: Wed, 18 Jan 2023 11:34:44 +0000 Subject: [PATCH] libtcmu: ensure we exactly match cfgstring against handler subtype Ensure we pattern match 'cfgstring' against handler type exactly. Ensure we pattern match the cfgstring prefix against 'tcm-user' exactly. Signed-off-by: Alex Reid --- libtcmu.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libtcmu.c b/libtcmu.c index 46a6fbcc..f9421025 100644 --- a/libtcmu.c +++ b/libtcmu.c @@ -371,7 +371,8 @@ static struct tcmulib_handler *find_handler(struct tcmulib_context *ctx, len = found_at - cfgstring; darray_foreach(handler, ctx->handlers) { - if (!strncmp(cfgstring, handler->subtype, len)) + /* Ensure we match exactly, not just a prefix match */ + if (!strncmp(cfgstring, handler->subtype, len) && handler->subtype[len] == '\0') return handler; } @@ -438,9 +439,10 @@ static bool device_parse_cfg(struct tcmu_device *dev, /* Check valid cfgstring */ oldptr = cfgstring; ptr = strchr(oldptr, '/'); + len = ptr-oldptr; if (!ptr) goto err_badcfg; - if (strncmp(cfgstring, "tcm-user", ptr-oldptr)) + if (strncmp(cfgstring, "tcm-user", len) || cfgstring[len] != '/') goto err_badcfg; /* Get HBA name */