From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2B0B696FF1 for ; Fri, 27 Jan 2023 11:43:46 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 0548074D2 for ; Fri, 27 Jan 2023 11:43:16 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 27 Jan 2023 11:43:15 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 254E946031 for ; Fri, 27 Jan 2023 11:43:15 +0100 (CET) Date: Fri, 27 Jan 2023 11:43:14 +0100 From: Wolfgang Bumiller To: Leo Nunner Cc: pve-devel@lists.proxmox.com Message-ID: <20230127104314.luhpwskk5bgbdk5l@fwblub> References: <20230126143020.150338-1-l.nunner@proxmox.com> <20230126143020.150338-2-l.nunner@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230126143020.150338-2-l.nunner@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 2.699 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_HI -5 Sender listed at https://www.dnswl.org/, high trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [ipset.pm, groups.pm, aliases.pm] Subject: Re: [pve-devel] [PATCH firewall 1/4] api: factor out renaming parameters to more descriptive names X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jan 2023 10:43:46 -0000 On Thu, Jan 26, 2023 at 03:30:16PM +0100, Leo Nunner wrote: > Signed-off-by: Leo Nunner > --- > 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);