[pbs-devel] [PATCH proxmox-backup 2/3] tape: changer: handle libraries that sends wrong amount of data
Dominik Csapak
d.csapak at proxmox.com
Wed Jul 28 12:05:10 CEST 2021
if the library sends more data than advertised, simply cut it off,
but if it sends less data, bail out (depending on how much data is
missing, trying to parse it could lead to a panic, so bail out early)
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/tape/changer/sg_pt_changer.rs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/tape/changer/sg_pt_changer.rs b/src/tape/changer/sg_pt_changer.rs
index 2c5434f6..7ff9bc9d 100644
--- a/src/tape/changer/sg_pt_changer.rs
+++ b/src/tape/changer/sg_pt_changer.rs
@@ -692,6 +692,15 @@ fn decode_element_status_page(
bail!("got wrong first_element_address_reported"); // sanity check
}
+ let len = head.byte_count_of_report_available;
+ let len = ((len[0] as usize) << 16) + ((len[1] as usize) << 8) + (len[2] as usize);
+
+ if len < reader.len() {
+ reader = &reader[..len];
+ } else if len > reader.len() {
+ bail!("wrong amount of data: expected {}, got {}", len, reader.len());
+ }
+
loop {
if reader.is_empty() {
break;
--
2.30.2
More information about the pbs-devel
mailing list