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 2/2] file_size_info: cast 'size' and 'used' to integer
Date: Fri, 18 Feb 2022 08:36:03 +0100	[thread overview]
Message-ID: <bb7dbe75-260d-c895-2585-48a67781e996@proxmox.com> (raw)
In-Reply-To: <20220217145459.400284-2-m.limbeck@proxmox.com>

Am 17.02.22 um 15:54 schrieb Mira Limbeck:
> `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>
> ---
> v2:
>  - reworded commit subject and message
> 
>  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

Nit: Not sure if it's worth to put such a lengthy comment rather than
something like "coerce back from string". One can still read the commit
message in the git history if there ever is confusion about why it's there.

> +    $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




  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 [pve-devel] [PATCH v2 storage 1/2] fix #3894: " 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 [this message]
2022-02-18  7:36 ` [pve-devel] [PATCH v2 storage 1/2] fix #3894: " Fabian Ebner

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=bb7dbe75-260d-c895-2585-48a67781e996@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