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 5C4FA75C21 for ; Fri, 15 Oct 2021 10:08:05 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 477E025A05 for ; Fri, 15 Oct 2021 10:07:35 +0200 (CEST) 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 id 8D5FE259A4 for ; Fri, 15 Oct 2021 10:07:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 5D3C846526 for ; Fri, 15 Oct 2021 10:07:33 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Fri, 15 Oct 2021 10:07:30 +0200 Message-Id: <20211015080730.1427860-3-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211015080730.1427860-1-d.csapak@proxmox.com> References: <20211015080730.1427860-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.295 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: [pbs-devel] [RFC PATCH proxmox-backup 1/1] rest-server: tasks: percent-encode the task status line X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Oct 2021 08:08:05 -0000 we always want the status line of the task log to be a single line (makes the parsing easier), for that purpose, percent-encode it (we can decode it again when we need to) Signed-off-by: Dominik Csapak --- pbs-tools/src/percent_encoding.rs | 5 +++++ proxmox-rest-server/src/worker_task.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pbs-tools/src/percent_encoding.rs b/pbs-tools/src/percent_encoding.rs index afe011e2..dae9a50d 100644 --- a/pbs-tools/src/percent_encoding.rs +++ b/pbs-tools/src/percent_encoding.rs @@ -20,3 +20,8 @@ pub const DEFAULT_ENCODE_SET: &AsciiSet = &percent_encoding::CONTROLS // 0..1f a pub fn percent_encode_component(comp: &str) -> String { utf8_percent_encode(comp, percent_encoding::NON_ALPHANUMERIC).to_string() } + +/// percent encode control characters in a string +pub fn percent_encode_control_characters(comp: &str) -> String { + utf8_percent_encode(comp, percent_encoding::CONTROLS).to_string() +} diff --git a/proxmox-rest-server/src/worker_task.rs b/proxmox-rest-server/src/worker_task.rs index fb0dea9b..fb101b50 100644 --- a/proxmox-rest-server/src/worker_task.rs +++ b/proxmox-rest-server/src/worker_task.rs @@ -23,6 +23,7 @@ use proxmox_schema::upid::UPID; use pbs_tools::task::WorkerTaskContext; use pbs_tools::logrotate::{LogRotate, LogRotateFiles}; +use pbs_tools::percent_encoding::percent_encode_control_characters; use crate::{CommandSocket, FileLogger, FileLogOptions}; @@ -853,7 +854,8 @@ impl WorkerTask { /// Log task result, remove task from running list pub fn log_result(&self, result: &Result<(), Error>) { let state = self.create_state(result); - self.log_message(state.result_text()); + // percent encode it to avoid control characters (e.g. newlines in the status line) + self.log_message(percent_encode_control_characters(&state.result_text())); WORKER_TASK_LIST.lock().unwrap().remove(&self.upid.task_id); let _ = self.setup.update_active_workers(None); -- 2.30.2