mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-15 13:40:00 +00:00
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: 24197a9f6c
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
87aa00de73
commit
c990256896
@ -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) {
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user