From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D44CB1FF13B for ; Wed, 22 Apr 2026 13:14:00 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 3174E169A4; Wed, 22 Apr 2026 13:13:50 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 07/54] common: prevent autovivification in plugin_get_vtype_subdir helper Date: Wed, 22 Apr 2026 13:12:33 +0200 Message-ID: <20260422111322.257380-8-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260422111322.257380-1-m.carrara@proxmox.com> References: <20260422111322.257380-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: 1776856322420 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.086 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: 75ML6YMXAOM2TBRYSNUWUMGPCD4SNWBE X-Message-ID-Hash: 75ML6YMXAOM2TBRYSNUWUMGPCD4SNWBE 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 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 [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; } 1; -- 2.47.3