]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Ensure disk names follow the disk name regex
authorNitesh Konkar <niteshkonkar.libvirt@gmail.com>
Wed, 15 Feb 2017 11:14:58 +0000 (16:44 +0530)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 16 Feb 2017 08:59:13 +0000 (09:59 +0100)
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 <nitkon12@linux.vnet.ibm.com>
src/util/virutil.c
tests/utiltest.c

index 91178d151570d20c6a7062def8c463b9004a98a2..2796671f4a0e1a75d02f4fc25532eda38857cfa0 100644 (file)
@@ -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++) {
index 9b7a4a34f9fd3488a7d6255c8ce8a0a11e19e150..bd55d447b177ed9ec9da380aa10b860842033090 100644 (file)
@@ -37,7 +37,8 @@ static struct testDiskName diskNamesPart[] = {
 };
 
 static const char* diskNamesInvalid[] = {
-    "sda00", "sda01", "sdb-1"
+    "sda00", "sda01", "sdb-1",
+    "vd2"
 };
 
 static int