]> git.proxmox.com Git - pve-storage.git/commitdiff
file_size_info: cast 'size' and 'used' to integer
authorMira Limbeck <m.limbeck@proxmox.com>
Fri, 18 Feb 2022 08:58:27 +0000 (09:58 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 21 Feb 2022 15:07:30 +0000 (16:07 +0100)
`qemu-img info --output=json` returns the size and used values as integers in
the JSON format, but the regex match converts them to strings.
As we know they only contain digits, we can simply cast them back to integers
after the regex.

The API requires them to be integers.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage/Plugin.pm

index 12f1b4bb8336db350cda6dd38b0fac6dee2b1ab1..a6b0bddf737362ac39048e41b76d93a566b6eb75 100644 (file)
@@ -892,7 +892,11 @@ sub file_size_info {
     my ($size, $format, $used, $parent) = $info->@{qw(virtual-size format actual-size backing-filename)};
 
     ($size) = ($size =~ /^(\d+)$/) or die "size '$size' not an integer\n"; # untaint
+    # coerce back from string
+    $size = int($size);
     ($used) = ($used =~ /^(\d+)$/) or die "used '$used' not an integer\n"; # untaint
+    # coerce back from string
+    $used = int($used);
     ($format) = ($format =~ /^(\S+)$/) or die "format '$format' includes whitespace\n"; # untaint
     if (defined($parent)) {
        ($parent) = ($parent =~ /^(\S+)$/) or die "parent '$parent' includes whitespace\n"; # untaint