]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/CLIFormatter.pm
fix #1914: CLIFormatter: check also for existence of 'type'
[pve-common.git] / src / PVE / CLIFormatter.pm
index 2c10318d3b7c8e9a2e32c0e6e10fd2c366698c4e..3040323eff0f480fe096fbdf1be2c196e80181b3 100644 (file)
@@ -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);
@@ -412,7 +409,7 @@ sub print_api_result {
 
     my $format = $options->{'output-format'} // 'text';
 
-    if ($result_schema) {
+    if ($result_schema && defined($result_schema->{type})) {
        return if $result_schema->{type} eq 'null';
     } else {
        my $type = $guess_type->($data);