public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes
@ 2024-05-23 10:08 Dominik Csapak
  2024-05-24  7:50 ` Thomas Lamprecht
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2024-05-23 10:08 UTC (permalink / raw)
  To: pbs-devel

we have to check against the length of the attribute, not the u16
maximum value.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 pbs-tape/src/sg_tape/mam.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pbs-tape/src/sg_tape/mam.rs b/pbs-tape/src/sg_tape/mam.rs
index 4e995d0b..dc5163a5 100644
--- a/pbs-tape/src/sg_tape/mam.rs
+++ b/pbs-tape/src/sg_tape/mam.rs
@@ -169,7 +169,7 @@ pub fn write_mam_attribute<F: AsRawFd>(
     attr_data.extend(data);
     if !data.is_empty() && data.len() < attribute.len as usize {
         attr_data.resize(attr_data.len() - data.len() + attribute.len as usize, 0);
-    } else if data.len() > u16::MAX as usize {
+    } else if data.len() > attribute.len as usize {
         bail!("data to long");
     }
 
-- 
2.39.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes
  2024-05-23 10:08 [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes Dominik Csapak
@ 2024-05-24  7:50 ` Thomas Lamprecht
  2024-05-24  8:19   ` Dominik Csapak
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Lamprecht @ 2024-05-24  7:50 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Dominik Csapak

Am 23/05/2024 um 12:08 schrieb Dominik Csapak:
> we have to check against the length of the attribute, not the u16
> maximum value.
> 
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
>  pbs-tape/src/sg_tape/mam.rs | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/pbs-tape/src/sg_tape/mam.rs b/pbs-tape/src/sg_tape/mam.rs
> index 4e995d0b..dc5163a5 100644
> --- a/pbs-tape/src/sg_tape/mam.rs
> +++ b/pbs-tape/src/sg_tape/mam.rs
> @@ -169,7 +169,7 @@ pub fn write_mam_attribute<F: AsRawFd>(
>      attr_data.extend(data);
>      if !data.is_empty() && data.len() < attribute.len as usize {
>          attr_data.resize(attr_data.len() - data.len() + attribute.len as usize, 0);
> -    } else if data.len() > u16::MAX as usize {
> +    } else if data.len() > attribute.len as usize {
>          bail!("data to long");

Can we extend this error with the attribute name, the length we got and
the defined max length to have some more info for when a user runs into
this?

Something like:

bail!("attribute '{}' length {} is over the maximum allowed length {}", ...);

Or is this error already extended/concatenated with similar info somewhere
in the return chain (sorry, just doing a quick review directly in my MUA)


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes
  2024-05-24  7:50 ` Thomas Lamprecht
@ 2024-05-24  8:19   ` Dominik Csapak
  2024-05-24  8:26     ` Thomas Lamprecht
  0 siblings, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2024-05-24  8:19 UTC (permalink / raw)
  To: Thomas Lamprecht, Proxmox Backup Server development discussion

On 5/24/24 09:50, Thomas Lamprecht wrote:
> Am 23/05/2024 um 12:08 schrieb Dominik Csapak:
>> we have to check against the length of the attribute, not the u16
>> maximum value.
>>
>> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
>> ---
>>   pbs-tape/src/sg_tape/mam.rs | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/pbs-tape/src/sg_tape/mam.rs b/pbs-tape/src/sg_tape/mam.rs
>> index 4e995d0b..dc5163a5 100644
>> --- a/pbs-tape/src/sg_tape/mam.rs
>> +++ b/pbs-tape/src/sg_tape/mam.rs
>> @@ -169,7 +169,7 @@ pub fn write_mam_attribute<F: AsRawFd>(
>>       attr_data.extend(data);
>>       if !data.is_empty() && data.len() < attribute.len as usize {
>>           attr_data.resize(attr_data.len() - data.len() + attribute.len as usize, 0);
>> -    } else if data.len() > u16::MAX as usize {
>> +    } else if data.len() > attribute.len as usize {
>>           bail!("data to long");
> 
> Can we extend this error with the attribute name, the length we got and
> the defined max length to have some more info for when a user runs into
> this?
> 
> Something like:
> 
> bail!("attribute '{}' length {} is over the maximum allowed length {}", ...);
> 
> Or is this error already extended/concatenated with similar info somewhere
> in the return chain (sorry, just doing a quick review directly in my MUA)


it's logged with:

could not set MAM attribute {id}: {err}

and from the id we can infer the maximum length

but printing the expected/actual len probably make sense


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes
  2024-05-24  8:19   ` Dominik Csapak
@ 2024-05-24  8:26     ` Thomas Lamprecht
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Lamprecht @ 2024-05-24  8:26 UTC (permalink / raw)
  To: Dominik Csapak, Proxmox Backup Server development discussion

Am 24/05/2024 um 10:19 schrieb Dominik Csapak:
> On 5/24/24 09:50, Thomas Lamprecht wrote:
>> Am 23/05/2024 um 12:08 schrieb Dominik Csapak:
>>> +    } else if data.len() > attribute.len as usize {
>>>           bail!("data to long");
>>
>> Can we extend this error with the attribute name, the length we got and
>> the defined max length to have some more info for when a user runs into
>> this?
>>
>> Something like:
>>
>> bail!("attribute '{}' length {} is over the maximum allowed length {}", ...);
>>
>> Or is this error already extended/concatenated with similar info somewhere
>> in the return chain (sorry, just doing a quick review directly in my MUA)
> 
> 
> it's logged with:
> 
> could not set MAM attribute {id}: {err}

OK, thanks for checking.

> and from the id we can infer the maximum length

It still is nice for the end user to get to see that, if some (description
or label) attribute would become more free form in the future, even if
we'd say that's unlikely it's IMO just way to cheap to even thinking about
not doing it..

> 
> but printing the expected/actual len probably make sense
> 

Yeah, please print both, got and expected.



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-24  8:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-23 10:08 [pbs-devel] [PATCH proxmox-backup] tape: mam: actually enforcing the length when writing attributes Dominik Csapak
2024-05-24  7:50 ` Thomas Lamprecht
2024-05-24  8:19   ` Dominik Csapak
2024-05-24  8:26     ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal