From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id D20951FF0AA for ; Tue, 17 Nov 2026 21:40:55 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 187A021669; Tue, 17 Nov 2026 21:40:50 +0100 (CET) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v3 06/51] common: prevent autovivification in plugin_get_vtype_subdir helper Date: Tue, 17 Nov 2026 21:38:38 +0100 Message-ID: <20261117203953.913035-7-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261117203953.913035-1-m.carrara@proxmox.com> References: <20261117203953.913035-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794948006125 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.275 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: NFX432WAZEJUH6ZVY4JISX2WKFENFKQ3 X-Message-ID-Hash: NFX432WAZEJUH6ZVY4JISX2WKFENFKQ3 X-MailFrom: m.carrara@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: Wolfgang Bumiller X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 [1]. 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. [1]: https://perldoc.perl.org/perlref#Autovivification Signed-off-by: Max R. Carrara --- src/PVE/Storage/Common.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PVE/Storage/Common.pm b/src/PVE/Storage/Common.pm index 58f2adfa..4f5fde64 100644 --- a/src/PVE/Storage/Common.pm +++ b/src/PVE/Storage/Common.pm @@ -425,11 +425,13 @@ sub plugin_get_vtype_subdir : prototype($$) ($scfg, $vtype) { die "storage definition has no path\n" if !$path; $vtype = 'images' if is_guest_vtype($vtype); 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"; } 1; -- 2.47.3