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 2FF9876FD6 for ; Mon, 26 Apr 2021 15:20:57 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 25E9816520 for ; Mon, 26 Apr 2021 15:20:27 +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 AAA1616517 for ; Mon, 26 Apr 2021 15:20:26 +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 7B947428F9 for ; Mon, 26 Apr 2021 15:20:26 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Mon, 26 Apr 2021 15:20:25 +0200 Message-Id: <20210426132025.17758-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.000 Adjusted score from AWL reputation of From: address 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] [PATCH proxmox-backup v2] tools/sgutils2: improve error messages 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: Mon, 26 Apr 2021 13:20:57 -0000 include the expected and unexpected sizes in the error message, so that it's easier to debug in case of an error Signed-off-by: Dominik Csapak --- change from v1: * use local variable to prevent UB warning (borrow of packed fields) src/tools/sgutils2.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs index 5273173f..96625301 100644 --- a/src/tools/sgutils2.rs +++ b/src/tools/sgutils2.rs @@ -759,18 +759,21 @@ pub fn scsi_mode_sense( let head: ModeParameterHeader = unsafe { reader.read_be_value()? }; if (head.mode_data_len as usize + 2) != data.len() { - bail!("wrong mode_data_len"); + let len = head.mode_data_len; + bail!("wrong mode_data_len: {}, expected {}", len, data.len() - 2); } if disable_block_descriptor && head.block_descriptior_len != 0 { - bail!("wrong block_descriptior_len"); + let len = head.block_descriptior_len; + bail!("wrong block_descriptior_len: {}, expected 0", len); } let mut block_descriptor: Option = None; if !disable_block_descriptor { if head.block_descriptior_len != 8 { - bail!("wrong block_descriptior_len"); + let len = head.block_descriptior_len; + bail!("wrong block_descriptior_len: {}, expected 8", len); } block_descriptor = Some(unsafe { reader.read_be_value()? }); -- 2.20.1