mirror of
https://git.proxmox.com/git/pve-common
synced 2025-07-17 10:21:29 +00:00
render_bytes: avoid untaint by simply change the sprintf call
There is no need to untaint if we do it this way (no idea why).
This commit is contained in:
parent
a91ee28fe5
commit
3496d4bf4d
@ -69,9 +69,6 @@ PVE::JSONSchema::register_renderer(
|
|||||||
sub render_bytes {
|
sub render_bytes {
|
||||||
my ($value) = @_;
|
my ($value) = @_;
|
||||||
|
|
||||||
return $value if $value !~ m/^(\d+)$/;
|
|
||||||
$value = int($1); # untaint for sprintf
|
|
||||||
|
|
||||||
my @units = qw(B KiB MiB GiB TiB PiB);
|
my @units = qw(B KiB MiB GiB TiB PiB);
|
||||||
|
|
||||||
my $max_unit = 0;
|
my $max_unit = 0;
|
||||||
@ -79,8 +76,8 @@ sub render_bytes {
|
|||||||
$max_unit = int(log($value)/log(1024));
|
$max_unit = int(log($value)/log(1024));
|
||||||
$value /= 1024**($max_unit);
|
$value /= 1024**($max_unit);
|
||||||
}
|
}
|
||||||
|
my $unit = $units[$max_unit];
|
||||||
return sprintf "%.2f $units[$max_unit]", $value;
|
return sprintf "%.2f $unit", $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
|
PVE::JSONSchema::register_renderer('bytes', \&render_bytes);
|
||||||
|
Loading…
Reference in New Issue
Block a user