From c99025689644aae5cf6c427de4cd704dc9d352c7 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Fri, 5 May 2017 11:10:43 +0200 Subject: [PATCH] get_options: handle array and scalar refs on decoding 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 --- src/PVE/JSONSchema.pm | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/PVE/JSONSchema.pm b/src/PVE/JSONSchema.pm index 9c624f6..921dbb5 100644 --- a/src/PVE/JSONSchema.pm +++ b/src/PVE/JSONSchema.pm @@ -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) { - $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) { -- 2.39.2