public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com, Mira Limbeck <m.limbeck@proxmox.com>
Subject: Re: [pve-devel] [PATCH v2 storage 1/2] fix #3894: cast 'size' and 'used' to integer
Date: Fri, 18 Feb 2022 08:36:12 +0100	[thread overview]
Message-ID: <89ab4a23-dee4-bbf1-3d62-615f9f0985f9@proxmox.com> (raw)
In-Reply-To: <20220217145459.400284-1-m.limbeck@proxmox.com>

Am 17.02.22 um 15:54 schrieb Mira Limbeck:
> 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@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}));

Style nit: superfluous parentheses (of course the pre-existing one is to
blame ;))

>  	    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),

Style nit: please fix the pre-existing white-space error while modifying
the line

>  	    format => $format,
>  	};
>  

Just minor nits, so both patches:

Reviewed-by: Fabian Ebner <f.ebner@proxmox.com>




      parent reply	other threads:[~2022-02-18  7:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17 14:54 Mira Limbeck
2022-02-17 14:54 ` [pve-devel] [PATCH v2 storage 2/2] file_size_info: " Mira Limbeck
2022-02-18  7:36   ` Fabian Ebner
2022-02-18  7:36 ` Fabian Ebner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=89ab4a23-dee4-bbf1-3d62-615f9f0985f9@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=m.limbeck@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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