From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D484F8D2A1 for ; Mon, 7 Nov 2022 16:07:53 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id BE72F2D432 for ; Mon, 7 Nov 2022 16:07:53 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 7 Nov 2022 16:07:52 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2ABBB4247E for ; Mon, 7 Nov 2022 16:07:52 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 7 Nov 2022 16:07:49 +0100 Message-Id: <20221107150750.2320248-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.066 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 Subject: [pve-devel] [PATCH http-server v2 1/2] upload: allow whitespaces in filenames X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Nov 2022 15:07:53 -0000 some fields (e.g. filename) can contain spaces, but our 'trim' function, would only return the value until the first whitespace character instead of removing leading/trailing white space. this lead to giving the wrong filename to the api call (e.g. 'foo' instead of 'foo (1).iso') which would reject it because of the 'wrong' extension this patch fixes that by using trim from pve-common fixes commit: 0fbcbc2 ("fix #3990: multipart upload: rework to fix uploading small files") Signed-off-by: Dominik Csapak --- src/PVE/APIServer/AnyEvent.pm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm index 4296ded..39061ad 100644 --- a/src/PVE/APIServer/AnyEvent.pm +++ b/src/PVE/APIServer/AnyEvent.pm @@ -46,7 +46,7 @@ use URI; use PVE::INotify; use PVE::SafeSyslog; -use PVE::Tools; +use PVE::Tools qw(trim); use PVE::APIServer::Formatter; use PVE::APIServer::Utils; @@ -1186,11 +1186,6 @@ my sub assert_form_disposition { sub file_upload_multipart { my ($self, $reqstate, $auth, $method, $path, $rstate) = @_; - my $trim = sub { - $_[0] =~ /\s*(\S+)/; - return $1; - }; - eval { my $boundary = $rstate->{boundary}; my $hdl = $reqstate->{hdl}; @@ -1210,7 +1205,7 @@ sub file_upload_multipart { my ($name) = @_; if ($hdl->{rbuf} =~ s/^${delim_re}Content-Disposition: (.*?); name="$name"(.*?)($delim_re)/$3/s) { assert_form_disposition($1); - $rstate->{params}->{$name} = $trim->($2); + $rstate->{params}->{$name} = trim($2); } }; @@ -1228,7 +1223,7 @@ sub file_upload_multipart { assert_form_disposition($1); die "wrong field name '$2' for file upload, expected 'filename'" if $2 ne "filename"; $rstate->{phase} = 2; - $rstate->{params}->{filename} = $trim->($3); + $rstate->{params}->{filename} = trim($3); } } -- 2.30.2