From: Nicolas Frey <n.frey@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH 2/2] apiserver: check if file is directory before opening
Date: Wed, 15 Oct 2025 10:03:30 +0200 [thread overview]
Message-ID: <20251015080330.45927-3-n.frey@proxmox.com> (raw)
In-Reply-To: <20251015080330.45927-1-n.frey@proxmox.com>
Add a check for if the file being accessed is a directory.
This improves the error relayed to the user, which - when mistakenly
trying to access a directory instead of a file - would return:
`unable to detect content type at /usr/share/perl5/PVE/APIServer/AnyEvent.pm line 499.`
Signed-off-by: Nicolas Frey <n.frey@proxmox.com>
---
src/PVE/APIServer/AnyEvent.pm | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 36dee02..3a7fa1b 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -1252,6 +1252,9 @@ sub handle_request {
my ($subdir, $file) = ($1, $2);
if (my $dir = $self->{dirs}->{$subdir}) {
my $filename = "$dir$file";
+ if (-d $filename) {
+ die "unable to open file '$filename' because it is a directory\n";
+ }
my $fh = IO::File->new($filename)
|| die "unable to open file '$filename' - $!\n";
send_file_start($self, $reqstate, { path => $filename });
--
2.47.3
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
prev parent reply other threads:[~2025-10-15 8:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-15 8:03 [pve-devel] [PATCH 0/2] improve error message when accessing a directory Nicolas Frey
2025-10-15 8:03 ` [pve-devel] [PATCH 1/2] apiserver: fix typo Nicolas Frey
2025-10-15 8:03 ` Nicolas Frey [this message]
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=20251015080330.45927-3-n.frey@proxmox.com \
--to=n.frey@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox