tape: changer: handle invalid descriptor data from library in status page

We get the descriptor length from the library and use that in
'chunks_exact', which panics on length 0. Catch that case
and bail out, since that makes no sense here anyway.

This could prevent a panic, in case a library sends wrong data.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-07-26 09:20:41 +02:00 committed by Dietmar Maurer
parent 68e77657e6
commit 42b010174e

View File

@ -710,7 +710,13 @@ fn decode_element_status_page(
let descr_data = reader.read_exact_allocated(len)?;
for descriptor in descr_data.chunks_exact(subhead.descriptor_length as usize) {
let descr_len = subhead.descriptor_length as usize;
if descr_len == 0 {
bail!("got elements, but descriptor length 0");
}
for descriptor in descr_data.chunks_exact(descr_len) {
let mut reader = &descriptor[..];
match subhead.element_type_code {