]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDiskNameParse: Fix integer overflow in disk name parsing
authorPeter Krempa <pkrempa@redhat.com>
Mon, 9 Sep 2024 14:46:09 +0000 (16:46 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 10 Sep 2024 12:26:39 +0000 (14:26 +0200)
The conversion to index entails multiplication and accumulation by user
provided data which can easily overflow, use VIR_MULTIPLY_ADD_IS_OVERFLOW
to check if the string is valid.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/674
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/util/virutil.c

index dc5009f11d63b2421acf0b940f5e0040d7c976ef..6c89a48e5112b9731800fc6e6eaf550946ec2465 100644 (file)
@@ -338,11 +338,17 @@ int virDiskNameParse(const char *name, int *disk, int *partition)
         return -1;
 
     for (i = 0; *ptr; i++) {
+        int c = *ptr - 'a';
+
         if (!g_ascii_islower(*ptr))
             break;
 
-        idx = (idx + (i < 1 ? 0 : 1)) * 26;
-        idx += *ptr - 'a';
+        idx = (idx + (i < 1 ? 0 : 1));
+
+        if (VIR_MULTIPLY_ADD_IS_OVERFLOW(INT_MAX, idx, 26, c))
+            return -1;
+
+        idx = idx * 26 + c;
         ptr++;
     }