From 7bf404db3bed0976be457bd993ce6a2b4e019b12 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 31 Oct 2024 13:53:20 +0100 Subject: [PATCH] validate_lvname: early exit If the LV name does not any have '_' chr, there is no point trying to call 'strstr()' to look for "_suffix". Also we can search from _. --- lib/misc/lvm-string.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c index 8beb6a4ac..633f26b7f 100644 --- a/lib/misc/lvm-string.c +++ b/lib/misc/lvm-string.c @@ -172,6 +172,9 @@ static const char *_lvname_has_reserved_component_string(const char *lvname) }; unsigned i; + if (!(lvname = strchr(lvname, '_'))) + return NULL; + for (i = 0; i < DM_ARRAY_SIZE(_strings); ++i) if (strstr(lvname, _strings[i])) return _strings[i]; @@ -189,6 +192,9 @@ static const char *_lvname_has_reserved_string(const char *lvname) unsigned i; const char *cs; + if (!(lvname = strchr(lvname, '_'))) + return NULL; + if ((cs = _lvname_has_reserved_component_string(lvname))) return cs;