public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH v3 storage 1/2] fix #3894: cast 'size' and 'used' to integer
@ 2022-02-18  8:58 Mira Limbeck
  2022-02-18  8:58 ` [pve-devel] [PATCH storage v3 2/2] file_size_info: " Mira Limbeck
  2022-02-21 15:08 ` [pve-devel] applied: [PATCH v3 storage 1/2] fix #3894: " Thomas Lamprecht
  0 siblings, 2 replies; 4+ messages in thread
From: Mira Limbeck @ 2022-02-18  8:58 UTC (permalink / raw)
  To: pve-devel

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 call, add an
explicit cast to integer.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>
---
v3:
 - fixed style nits
 - added R-b tag
v2:
 - new

 PVE/API2/Storage/Content.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Storage/Content.pm b/PVE/API2/Storage/Content.pm
index 45b8de8..8ff858d 100644
--- a/PVE/API2/Storage/Content.pm
+++ b/PVE/API2/Storage/Content.pm
@@ -139,7 +139,9 @@ __PACKAGE__->register_method ({
 	foreach my $item (@$vollist) {
 	    eval {  PVE::Storage::check_volume_access($rpcenv, $authuser, $cfg, undef, $item->{volid}); };
 	    next if $@;
-	    $item->{vmid} = int($item->{vmid}) if (defined($item->{vmid}));
+	    $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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-21 15:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-18  8:58 [pve-devel] [PATCH v3 storage 1/2] fix #3894: cast 'size' and 'used' to integer Mira Limbeck
2022-02-18  8:58 ` [pve-devel] [PATCH storage v3 2/2] file_size_info: " Mira Limbeck
2022-02-21 15:08   ` [pve-devel] applied: " Thomas Lamprecht
2022-02-21 15:08 ` [pve-devel] applied: [PATCH v3 storage 1/2] fix #3894: " Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal