]> git.proxmox.com Git - pve-common.git/commitdiff
render_bytes: avoid untaint by simply change the sprintf call
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 6 Aug 2018 11:36:23 +0000 (13:36 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 6 Aug 2018 11:36:23 +0000 (13:36 +0200)
There is no need to untaint if we do it this way (no idea why).

src/PVE/CLIFormatter.pm

index 2c10318d3b7c8e9a2e32c0e6e10fd2c366698c4e..47021800956a806904aec6d885aadb2804bc8fa1 100644 (file)
@@ -69,9 +69,6 @@ PVE::JSONSchema::register_renderer(
 sub render_bytes {
     my ($value) = @_;
 
 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;
     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);
     }
         $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);
 }
 
 PVE::JSONSchema::register_renderer('bytes', \&render_bytes);