[PATCH 3/3] util: fix potential crash in virDiskNameParse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



As far as virDiskNameToIndex calls virDiskNameParse and doesn't
check parameters and in most cases is used with disk->dst as a
parameter and disk->dst is by virIndexToDiskName, which can
return NULL, virDiskNameParse can crash in such cases.
Let's be paranoic and sustain even such incorrect usage.

Signed-off-by: Maxim Nestratov <mnestratov@xxxxxxxxxxxxx>
---
 src/util/virutil.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index d80d994..05e136d 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -556,6 +556,9 @@ int virDiskNameParse(const char *name, int *disk, int *partition)
     static char const* const drive_prefix[] = {"fd", "hd", "vd", "sd", "xvd", "ubd"};
     size_t i;
 
+    if (!name)
+        return -1;
+
     for (i = 0; i < ARRAY_CARDINALITY(drive_prefix); i++) {
         if (STRPREFIX(name, drive_prefix[i])) {
             ptr = name + strlen(drive_prefix[i]);
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]