[pve-devel] [PATCH 2/2] apiserver: check if file is directory before opening
Nicolas Frey
n.frey at proxmox.com
Wed Oct 15 10:03:30 CEST 2025
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 at 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
More information about the pve-devel
mailing list