[pve-devel] [PATCH v2 storage 1/2] fix #3894: cast 'size' and 'used' to integer

Mira Limbeck m.limbeck at proxmox.com
Thu Feb 17 15:54:58 CET 2022


Perl's automatic conversion can lead to integers being converted to
strings, for example by matching it in a regex.

To make sure we always return an integer in the API calls, add
explicit casts to integer.

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
v2: new

 PVE/API2/Storage/Content.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm
index 45b8de8..42bff81 100644
--- a/PVE/API2/Storage/Content.pm
+++ b/PVE/API2/Storage/Content.pm
@@ -140,6 +140,8 @@ __PACKAGE__->register_method ({
 	    eval {  PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $item->{volid}); };
 	    next if $@;
 	    $item->{vmid} = int($item->{vmid}) if (defined($item->{vmid}));
+	    $item->{size} = int($item->{size}) if (defined($item->{size}));
+	    $item->{used} = int($item->{used}) if (defined($item->{used}));
 	    push @$res, $item;
 	}
 
@@ -326,8 +328,8 @@ __PACKAGE__->register_method ({
 
 	my $entry = {
 	    path => $path,
-	    size => $size,
-            used => $used,
+	    size => int($size), # cast to integer in case it was changed to a string previously
+            used => int($used),
 	    format => $format,
 	};
 
-- 
2.30.2






More information about the pve-devel mailing list