all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Leo Nunner <l.nunner@proxmox.com>
Cc: pve-devel@lists.proxmox.com
Subject: Re: [pve-devel] [PATCH firewall 1/4] api: factor out renaming parameters to more descriptive names
Date: Fri, 27 Jan 2023 11:43:14 +0100	[thread overview]
Message-ID: <20230127104314.luhpwskk5bgbdk5l@fwblub> (raw)
In-Reply-To: <20230126143020.150338-2-l.nunner@proxmox.com>

On Thu, Jan 26, 2023 at 03:30:16PM +0100, Leo Nunner wrote:
> Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
> ---
>  src/PVE/API2/Firewall/Aliases.pm | 20 ++++++------
>  src/PVE/API2/Firewall/Groups.pm  | 53 ++++++++++++++++----------------
>  src/PVE/API2/Firewall/IPSet.pm   | 39 ++++++++++++-----------
>  3 files changed, 56 insertions(+), 56 deletions(-)
> 
> diff --git a/src/PVE/API2/Firewall/Aliases.pm b/src/PVE/API2/Firewall/Aliases.pm
> index 33ac669..88f20a0 100644
> --- a/src/PVE/API2/Firewall/Aliases.pm
> +++ b/src/PVE/API2/Firewall/Aliases.pm
> @@ -234,24 +234,22 @@ sub register_update_alias {
>  
>  		PVE::Tools::assert_if_modified($digest, $param->{digest});
>  
> -		my $name = lc($param->{name});
> +		my $rename_to = lc($param->{rename}) if defined($param->{rename});

Conditional variable declaration leads to really bad undefined behavior
in perl, please keep this split in 2 as it was before, otherwise this
might retain values from previous times the api call was used...

> +		my $rename_from = lc($param->{name});
>  
> -		raise_param_exc({ name => "no such alias" }) if !$aliases->{$name};
> +		raise_param_exc({ name => "no such alias" }) if !$aliases->{$rename_from};
>  
>  		my $data = { name => $param->{name}, cidr => $param->{cidr} };
>  		$data->{comment} = $param->{comment} if $param->{comment};
>  
> -		$aliases->{$name} = $data;
> -
> -		my $rename = $param->{rename};
> -		$rename = lc($rename) if $rename;
> +		$aliases->{$rename_from} = $data;
>  
> -		if ($rename && ($name ne $rename)) {
> +		if ($rename_to && ($rename_from ne $rename_to)) {
>  		    raise_param_exc({ name => "alias '$param->{rename}' already exists" })
> -			if defined($aliases->{$rename});
> -		    $aliases->{$name}->{name} = $param->{rename};
> -		    $aliases->{$rename} = $aliases->{$name};
> -		    delete $aliases->{$name};
> +			if defined($aliases->{$rename_to});
> +		    $aliases->{$rename_from}->{name} = $param->{rename};
> +		    $aliases->{$rename_to} = $aliases->{$rename_from};
> +		    delete $aliases->{$rename_from};
>  		}
>  
>  		$class->save_aliases($param, $fw_conf, $aliases);




  reply	other threads:[~2023-01-27 10:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-26 14:30 [pve-devel] [PATCH firewall manager] Make firewall config case-insensitive Leo Nunner
2023-01-26 14:30 ` [pve-devel] [PATCH firewall 1/4] api: factor out renaming parameters to more descriptive names Leo Nunner
2023-01-27 10:43   ` Wolfgang Bumiller [this message]
2023-01-26 14:30 ` [pve-devel] [PATCH firewall 2/4] docs: clarify usage of 'rename' parameters Leo Nunner
2023-01-28 10:39   ` Thomas Lamprecht
2023-01-26 14:30 ` [pve-devel] [PATCH firewall 3/4] config: make groups, IPSets and aliases case-insensitive Leo Nunner
2023-01-26 14:30 ` [pve-devel] [PATCH firewall 4/4] config: combine group/ipset and their comments Leo Nunner
2023-01-27 11:41   ` Wolfgang Bumiller
2023-01-30  9:01     ` Leo Nunner
2023-01-26 14:30 ` [pve-devel] [PATCH manager] ui: the API doesn't pass 'name' for aliases anymore Leo Nunner
2023-01-28 10:43   ` Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230127104314.luhpwskk5bgbdk5l@fwblub \
    --to=w.bumiller@proxmox.com \
    --cc=l.nunner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal