[pve-devel] [PATCH storage] fix #3894: file 'size' and 'used' are not integers

Fabian Ebner f.ebner at proxmox.com
Thu Feb 17 14:24:19 CET 2022


Am 17.02.22 um 13:55 schrieb Mira Limbeck:
> 'qemu-img info' with output format 'json' returns the size and used values as
> integers, 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.
> 

Any reason for not doing it in the API call itself? That would cover all
plugins and future changes.

> Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
> ---
>  PVE/Storage/Plugin.pm | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
> index 12f1b4b..bcc0cc0 100644
> --- a/PVE/Storage/Plugin.pm
> +++ b/PVE/Storage/Plugin.pm
> @@ -892,7 +892,13 @@ 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
> +    # the regex above changes the type of $size to 'string'
> +    # we know it is an integer based on the regex above, so simply cast it back
> +    # this is required by the API
> +    $size = int($size);
>      ($used) = ($used =~ /^(\d+)$/) or die "used '$used' not an integer\n"; # untaint
> +    # same as $size above
> +    $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





More information about the pve-devel mailing list