From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 91F9C1FF146 for ; Tue, 28 Apr 2026 17:02:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 6450F178F3; Tue, 28 Apr 2026 17:02:28 +0200 (CEST) Date: Tue, 28 Apr 2026 17:02:19 +0200 From: Wolfgang Bumiller To: "Max R. Carrara" Subject: Re: [PATCH pve-storage v1 07/54] common: prevent autovivification in plugin_get_vtype_subdir helper Message-ID: References: <20260422111322.257380-1-m.carrara@proxmox.com> <20260422111322.257380-8-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260422111322.257380-8-m.carrara@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1777388443080 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.088 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 6PMGDEK2F4GOPQXZ4OEOQ54E7ZIWEK66 X-Message-ID-Hash: 6PMGDEK2F4GOPQXZ4OEOQ54E7ZIWEK66 X-MailFrom: w.bumiller@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pve-devel@lists.proxmox.com X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Wed, Apr 22, 2026 at 01:12:33PM +0200, Max R. Carrara wrote: > When accessing a non-existing (or undefined) value in a hash(ref) and > using this value again for a hash lookup, i.e. > `$hashref->{foo}->{bar}` where `$hashref->{foo}` does not exist or is > `undef`, Perl will (un)conveniently instantiate a new hashref where > one was absent before. This is also called autovivification [0]. > > This means that if the config hash of directory-based storage plugin > that does *not* declare the 'content-dirs' property in its `options()` > is passed to `plugin_get_vtype_subdir()`, the 'content-dirs' key will > be instantiated as an empty hashref during the > `$scfg->{'content-dirs'}->{$vtype}` lookup. > > Note that "directory-based storage plugin" means any storage plugin > that defines the 'path' property in its `options()` method. > > While this is a minor issue, the `$scfg` hashref should IMO never be > modified unless necessary, or if the method actually is supposed to > modify it. > > Therefore, prevent this autovivification [0] in > `plugin_get_vtype_subdir()`. > > Additionally, use string concatenation instead of interpolation for > the returned subdirectory path. > > [0]: https://perldoc.perl.org/perlref#Autovivification > > Signed-off-by: Max R. Carrara > --- > src/PVE/Storage/Common.pm | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm > index 52bd627d..abccf52b 100644 > --- a/src/PVE/Storage/Common.pm > +++ b/src/PVE/Storage/Common.pm > @@ -330,9 +330,11 @@ sub plugin_get_vtype_subdir : prototype($$) ($scfg, $vtype) { > die "storage definition has no path\n" if !$path; > die "unknown vtype '$vtype'\n" if !exists($DEFAULT_VTYPE_SUBDIRS->{$vtype}); > > - my $subdir = $scfg->{"content-dirs"}->{$vtype} // $DEFAULT_VTYPE_SUBDIRS->{$vtype}; > + # Intermediate step to prevent autovivification > + my $content_dirs = $scfg->{'content-dirs'} // {}; > + my $subdir = $content_dirs->{$vtype} // $DEFAULT_VTYPE_SUBDIRS->{$vtype}; > > - return "$path/$subdir"; > + return $path . '/' . $subdir; I don't mind - but why? > } > > 1; > -- > 2.47.3 > > > > > --