From 3496d4bf4d69213e9f211b64d63a54a63c9e5b16 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Mon, 6 Aug 2018 13:36:23 +0200 Subject: [PATCH 1/1] 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). --- src/PVE/CLIFormatter.pm | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/PVE/CLIFormatter.pm b/src/PVE/CLIFormatter.pm index 2c10318..4702180 100644 --- a/src/PVE/CLIFormatter.pm +++ b/src/PVE/CLIFormatter.pm @@ -69,9 +69,6 @@ PVE::JSONSchema::register_renderer( sub render_bytes { my ($value) = @_; - return $value if $value !~ m/^(\d+)$/; - $value = int($1); # untaint for sprintf - my @units = qw(B KiB MiB GiB TiB PiB); my $max_unit = 0; @@ -79,8 +76,8 @@ sub render_bytes { $max_unit = int(log($value)/log(1024)); $value /= 1024**($max_unit); } - - return sprintf "%.2f $units[$max_unit]", $value; + my $unit = $units[$max_unit]; + return sprintf "%.2f $unit", $value; } PVE::JSONSchema::register_renderer('bytes', \&render_bytes); -- 2.39.2