(remote) export: check and untaint format

this format comes from the remote cluster, so it might not be supported
on the source side - checking whether it's known (as additional
safeguard) and untainting (to avoid open3 failure) is required.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
 [ T: squashed in canonical perl array ref access ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Fabian Grünbichler
2022-09-28 14:50:59 +02:00
committed by Thomas Lamprecht
parent 47d1125bfe
commit 71460c8ace
2 changed files with 10 additions and 4 deletions

View File

@ -48,6 +48,8 @@ use constant APIVER => 10;
# see https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
use constant APIAGE => 1;
our $KNOWN_EXPORT_FORMATS = ['raw+size', 'tar+size', 'qcow2+size', 'vmdk+size', 'zfs', 'btrfs'];
# load standard plugins
PVE::Storage::DirPlugin->register();
PVE::Storage::LVMPlugin->register();
@ -1949,6 +1951,12 @@ sub volume_import_start {
sub volume_export_start {
my ($cfg, $volid, $format, $log, $opts) = @_;
my $known_format = [ grep { $_ eq $format } $KNOWN_EXPORT_FORMATS->@* ];
if (!$known_format->@*) {
die "Cannot export '$volid' using unknown export format '$format'\n";
}
$format = $known_format->[0];
my $run_command_params = delete $opts->{cmd} // {};
my $cmds = $volume_export_prepare->($cfg, $volid, $format, $log, $opts);