]> git.proxmox.com Git - pve-common.git/commitdiff
get_options: handle array and scalar refs on decoding
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 5 May 2017 09:10:43 +0000 (11:10 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 5 May 2017 10:37:50 +0000 (12:37 +0200)
get_options is for parsing CLI options, here we decode after using
Getopt as we are not sure how well it handles already decoded data.
But as Gettopt can produces references for the parsed data we must
handle them explictily.
So check if we have a ARRAY or SCALAR reference and decode them
respectively.
All other reference types should not get returned from Getopt so
error out on them.

This bug was seen when viewing backup jobs, as we save the job as a
comand entry in /etc/pve/vzdump.cron and parse it then with this
function on reading.
Besides the use there we use it in the RESTHandler Packages
cli_handler sub method, so some CLI tools could be possibly affected
by this.

Fixes: 24197a9f6c698985b7255fbf7792b0b6bd8188b5
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/JSONSchema.pm

index 9c624f694c6f423ee643ef025620c369b713f5bb..921dbb5000d2fb8c6bbc35d8621268dfbd66dddf 100644 (file)
@@ -1351,8 +1351,21 @@ sub get_options {
        }
     }
 
        }
     }
 
+    # decode after Getopt as we are not sure how well it handles unicode
     foreach my $p (keys %$opts) {
     foreach my $p (keys %$opts) {
-       $opts->{$p} = decode('locale', $opts->{$p});
+       if (!ref($opts->{$p})) {
+           $opts->{$p} = decode('locale', $opts->{$p});
+       } elsif (ref($opts->{$p}) eq 'ARRAY') {
+           my $tmp = [];
+           foreach my $v (@{$opts->{$p}}) {
+               push @$tmp, decode('locale', $v);
+           }
+           $opts->{$p} = $tmp;
+       } elsif (ref($opts->{$p}) eq 'SCALAR') {
+           $opts->{$p} = decode('locale', $$opts->{$p});
+       } else {
+           raise("decoding options failed, unknown reference\n", code => HTTP_BAD_REQUEST);
+       }
     }
 
     foreach my $p (keys %$opts) {
     }
 
     foreach my $p (keys %$opts) {