]> git.proxmox.com Git - pve-storage.git/commitdiff
(remote) export: check and untaint format
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 28 Sep 2022 12:50:59 +0000 (14:50 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 29 Sep 2022 12:21:08 +0000 (14:21 +0200)
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>
PVE/CLI/pvesm.pm
PVE/Storage.pm

index 003b019e9af769561234e04dde5479d00ba95271..9b9676b4a2864a2368bf3c3ba436ddca8047a4bf 100755 (executable)
@@ -30,8 +30,6 @@ use PVE::CLIHandler;
 
 use base qw(PVE::CLIHandler);
 
-my $KNOWN_EXPORT_FORMATS = ['raw+size', 'tar+size', 'qcow2+size', 'vmdk+size', 'zfs', 'btrfs'];
-
 my $nodename = PVE::INotify::nodename();
 
 sub param_mapping {
@@ -269,7 +267,7 @@ __PACKAGE__->register_method ({
            format => {
                description => "Export stream format",
                type => 'string',
-               enum => $KNOWN_EXPORT_FORMATS,
+               enum => $PVE::Storage::KNOWN_EXPORT_FORMATS,
            },
            filename => {
                description => "Destination file name",
@@ -355,7 +353,7 @@ __PACKAGE__->register_method ({
            format => {
                description => "Import stream format",
                type => 'string',
-               enum => $KNOWN_EXPORT_FORMATS,
+               enum => $PVE::Storage::KNOWN_EXPORT_FORMATS,
            },
            filename => {
                description => "Source file name. For '-' stdin is used, the " .
index b9c53a11dda2f4fdd94c1298535b02385c6d172b..c21b85e54e56e84e1fd19ca2849636ffdbfbdaf4 100755 (executable)
@@ -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);