From 5729746543cf4df5c7b1adea877b4fe45bf67e51 Mon Sep 17 00:00:00 2001 From: Nitesh Konkar Date: Wed, 15 Feb 2017 16:44:58 +0530 Subject: [PATCH] Ensure disk names follow the disk name regex Currently disk names do not follow the (regex) /^[fhv]d[a-z]+[0-9]*$/ completely and hence one can assign disk names like vd2 etc. This patch ensures that the disk names follow the regex mentioned. This patch also adds a testcase. Signed-off-by: Nitesh Konkar --- src/util/virutil.c | 2 +- tests/utiltest.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 91178d1515..2796671f4a 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -563,7 +563,7 @@ int virDiskNameParse(const char *name, int *disk, int *partition) } } - if (!ptr) + if (!ptr || !c_islower(*ptr)) return -1; for (i = 0; *ptr; i++) { diff --git a/tests/utiltest.c b/tests/utiltest.c index 9b7a4a34f9..bd55d447b1 100644 --- a/tests/utiltest.c +++ b/tests/utiltest.c @@ -37,7 +37,8 @@ static struct testDiskName diskNamesPart[] = { }; static const char* diskNamesInvalid[] = { - "sda00", "sda01", "sdb-1" + "sda00", "sda01", "sdb-1", + "vd2" }; static int -- GitLab