[pve-devel] applied: [RFC common] get_options: handle array and scalar refs on decoding
Fabian Grünbichler
f.gruenbichler at proxmox.com
Fri May 5 12:40:15 CEST 2017
On Fri, May 05, 2017 at 11:10:43AM +0200, Thomas Lamprecht wrote:
> 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 at proxmox.com>
> ---
> 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..b30d6a8 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.11.0
>
>
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
More information about the pve-devel
mailing list